aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ext_depends/D-YAML/source/dyaml/test/inputoutput.d
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2021-02-19 17:10:51 -0500
committerRalph Amissah <ralph.amissah@gmail.com>2021-02-24 16:46:47 -0500
commit02ca32ae0a5bc290918d2b2a3288e385b9cc6b11 (patch)
tree06379785e8a0165a7deb981c2eba362894820634 /src/ext_depends/D-YAML/source/dyaml/test/inputoutput.d
parentbuild from static source-tree pre fetch depends (diff)
external & build dependences in src tree
- external & build dependences boost licensed - ext_depends (external depends) - D-YAML - tinyendian - d2sqlite3 - imageformats - build_depends - dub2nix
Diffstat (limited to 'src/ext_depends/D-YAML/source/dyaml/test/inputoutput.d')
-rw-r--r--src/ext_depends/D-YAML/source/dyaml/test/inputoutput.d92
1 files changed, 92 insertions, 0 deletions
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"]);
+}