From 02ca32ae0a5bc290918d2b2a3288e385b9cc6b11 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 19 Feb 2021 17:10:51 -0500 Subject: external & build dependences in src tree - external & build dependences boost licensed - ext_depends (external depends) - D-YAML - tinyendian - d2sqlite3 - imageformats - build_depends - dub2nix --- .../D-YAML/source/dyaml/test/inputoutput.d | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/inputoutput.d (limited to 'src/ext_depends/D-YAML/source/dyaml/test/inputoutput.d') diff --git a/src/ext_depends/D-YAML/source/dyaml/test/inputoutput.d b/src/ext_depends/D-YAML/source/dyaml/test/inputoutput.d new file mode 100644 index 0000000..758def8 --- /dev/null +++ b/src/ext_depends/D-YAML/source/dyaml/test/inputoutput.d @@ -0,0 +1,92 @@ + +// Copyright Ferdinand Majerech 2011-2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +module dyaml.test.inputoutput; + +@safe unittest +{ + import std.array : join, split; + import std.conv : to; + import std.exception : assertThrown; + import std.file : readText; + import std.system : endian, Endian; + + import dyaml : Loader, Node, YAMLException; + import dyaml.test.common : run; + + /** + Get an UTF-16 byte order mark. + + Params: wrong = Get the incorrect BOM for this system. + + Returns: UTF-16 byte order mark. + */ + static wchar bom16(bool wrong = false) pure @safe + { + wchar little = '\uFEFF'; + wchar big = '\uFFFE'; + if (!wrong) + { + return endian == Endian.littleEndian ? little : big; + } + return endian == Endian.littleEndian ? big : little; + } + /** + Get an UTF-32 byte order mark. + + Params: wrong = Get the incorrect BOM for this system. + + Returns: UTF-32 byte order mark. + */ + static dchar bom32(bool wrong = false) pure @safe + { + dchar little = '\uFEFF'; + dchar big = '\uFFFE'; + if (!wrong) + { + return endian == Endian.littleEndian ? little : big; + } + return endian == Endian.littleEndian ? big : little; + } + /** + Unicode input unittest. Tests various encodings. + + Params: unicodeFilename = File name to read from. + */ + static void testUnicodeInput(string unicodeFilename) @safe + { + string data = readText(unicodeFilename); + string expected = data.split().join(" "); + + Node output = Loader.fromString(data).load(); + assert(output.as!string == expected); + + foreach (buffer; [cast(ubyte[]) (bom16() ~ data.to!(wchar[])), + cast(ubyte[]) (bom32() ~ data.to!(dchar[]))]) + { + output = Loader.fromBuffer(buffer).load(); + assert(output.as!string == expected); + } + } + /** + Unicode input error unittest. Tests various encodings with incorrect BOMs. + + Params: unicodeFilename = File name to read from. + */ + static void testUnicodeInputErrors(string unicodeFilename) @safe + { + string data = readText(unicodeFilename); + foreach (buffer; [cast(ubyte[]) (data.to!(wchar[])), + cast(ubyte[]) (data.to!(dchar[])), + cast(ubyte[]) (bom16(true) ~ data.to!(wchar[])), + cast(ubyte[]) (bom32(true) ~ data.to!(dchar[]))]) + { + assertThrown(Loader.fromBuffer(buffer).load()); + } + } + run(&testUnicodeInput, ["unicode"]); + run(&testUnicodeInputErrors, ["unicode"]); +} -- cgit v1.2.3