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 --- src/ext_depends/D-YAML/source/dyaml/test/common.d | 223 +++++ src/ext_depends/D-YAML/source/dyaml/test/compare.d | 51 ++ .../D-YAML/source/dyaml/test/constructor.d | 957 +++++++++++++++++++++ src/ext_depends/D-YAML/source/dyaml/test/emitter.d | 132 +++ src/ext_depends/D-YAML/source/dyaml/test/errors.d | 64 ++ .../D-YAML/source/dyaml/test/inputoutput.d | 92 ++ src/ext_depends/D-YAML/source/dyaml/test/reader.d | 37 + .../D-YAML/source/dyaml/test/representer.d | 54 ++ .../D-YAML/source/dyaml/test/resolver.d | 39 + src/ext_depends/D-YAML/source/dyaml/test/tokens.d | 93 ++ 10 files changed, 1742 insertions(+) create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/common.d create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/compare.d create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/constructor.d create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/emitter.d create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/errors.d create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/inputoutput.d create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/reader.d create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/representer.d create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/resolver.d create mode 100644 src/ext_depends/D-YAML/source/dyaml/test/tokens.d (limited to 'src/ext_depends/D-YAML/source/dyaml/test') diff --git a/src/ext_depends/D-YAML/source/dyaml/test/common.d b/src/ext_depends/D-YAML/source/dyaml/test/common.d new file mode 100644 index 0000000..a6bafa9 --- /dev/null +++ b/src/ext_depends/D-YAML/source/dyaml/test/common.d @@ -0,0 +1,223 @@ + +// Copyright Ferdinand Majerech 2011. +// 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.common; + +version(unittest) +{ + +import dyaml.node; +import dyaml.event; + +import core.exception; +import std.algorithm; +import std.array; +import std.conv; +import std.file; +import std.range; +import std.path; +import std.traits; +import std.typecons; + +package: + +/** +Run a test. + +Params: + testFunction = Unittest function. + unittestExt = Extensions of data files needed for the unittest. + skipExt = Extensions that must not be used for the unittest. + */ +void run(D)(D testFunction, string[] unittestExt, string[] skipExt = []) +{ + immutable string dataDir = __FILE_FULL_PATH__.dirName ~ "/../../../test/data"; + auto testFilenames = findTestFilenames(dataDir); + + if (unittestExt.length > 0) + { + outer: foreach (base, extensions; testFilenames) + { + string[] filenames; + foreach (ext; unittestExt) + { + if (!extensions.canFind(ext)) + { + continue outer; + } + filenames ~= base ~ '.' ~ ext; + } + foreach (ext; skipExt) + { + if (extensions.canFind(ext)) + { + continue outer; + } + } + + execute(testFunction, filenames); + } + } + else + { + execute(testFunction, string[].init); + } +} + +// TODO: remove when a @safe ubyte[] file read can be done. +/** +Reads a file as an array of bytes. + +Params: + filename = Full path to file to read. + +Returns: The file's data. +*/ +ubyte[] readData(string filename) @trusted +{ + import std.file : read; + return cast(ubyte[])read(filename); +} +void assertNodesEqual(const scope Node gotNode, const scope Node expectedNode) @safe +{ + import std.format : format; + assert(gotNode == expectedNode, format!"got %s, expected %s"(gotNode.debugString, expectedNode.debugString)); +} + +/** +Determine if events in events1 are equivalent to events in events2. + +Params: + events1 = A range of events to compare with. + events2 = A second range of events to compare. + +Returns: true if the events are equivalent, false otherwise. +*/ +bool compareEvents(T, U)(T events1, U events2) +if (isInputRange!T && isInputRange!U && is(ElementType!T == Event) && is(ElementType!U == Event)) +{ + foreach (e1, e2; zip(events1, events2)) + { + //Different event types. + if (e1.id != e2.id) + { + return false; + } + //Different anchor (if applicable). + if (e1.id.among!(EventID.sequenceStart, EventID.mappingStart, EventID.alias_, EventID.scalar) + && e1.anchor != e2.anchor) + { + return false; + } + //Different collection tag (if applicable). + if (e1.id.among!(EventID.sequenceStart, EventID.mappingStart) && e1.tag != e2.tag) + { + return false; + } + if (e1.id == EventID.scalar) + { + //Different scalar tag (if applicable). + if (!(e1.implicit || e2.implicit) && e1.tag != e2.tag) + { + return false; + } + //Different scalar value. + if (e1.value != e2.value) + { + return false; + } + } + } + return true; +} +/** +Throw an Error if events in events1 aren't equivalent to events in events2. + +Params: + events1 = First event array to compare. + events2 = Second event array to compare. +*/ +void assertEventsEqual(T, U)(T events1, U events2) +if (isInputRange!T && isInputRange!U && is(ElementType!T == Event) && is(ElementType!U == Event)) +{ + auto events1Copy = events1.array; + auto events2Copy = events2.array; + assert(compareEvents(events1Copy, events2Copy), text("Got '", events1Copy, "', expected '", events2Copy, "'")); +} + +private: + +/** +Find unittest input filenames. + +Params: dir = Directory to look in. + +Returns: Test input base filenames and their extensions. +*/ + //@trusted due to dirEntries +string[][string] findTestFilenames(const string dir) @trusted +{ + //Groups of extensions indexed by base names. + string[][string] names; + foreach (string name; dirEntries(dir, SpanMode.shallow)) + { + if (isFile(name)) + { + string base = name.stripExtension(); + string ext = name.extension(); + if (ext is null) + { + ext = ""; + } + if (ext[0] == '.') + { + ext = ext[1 .. $]; + } + + //If the base name doesn't exist yet, add it; otherwise add new extension. + names[base] = ((base in names) is null) ? [ext] : names[base] ~ ext; + } + } + return names; +} + +/** +Recursively copy an array of strings to a tuple to use for unittest function input. + +Params: + index = Current index in the array/tuple. + tuple = Tuple to copy to. + strings = Strings to copy. +*/ +void stringsToTuple(uint index, F ...)(ref F tuple, const string[] strings) +in(F.length == strings.length) +do +{ + tuple[index] = strings[index]; + static if (index > 0) + { + stringsToTuple!(index - 1, F)(tuple, strings); + } +} + +/** +Execute an unittest on specified files. + +Params: + testName = Name of the unittest. + testFunction = Unittest function. + filenames = Names of input files to test with. + */ +void execute(D)(D testFunction, string[] filenames) +{ + //Convert filenames to parameters tuple and call the test function. + alias F = Parameters!D[0..$]; + F parameters; + stringsToTuple!(F.length - 1, F)(parameters, filenames); + testFunction(parameters); +} + +} // version(unittest) diff --git a/src/ext_depends/D-YAML/source/dyaml/test/compare.d b/src/ext_depends/D-YAML/source/dyaml/test/compare.d new file mode 100644 index 0000000..5a37fd0 --- /dev/null +++ b/src/ext_depends/D-YAML/source/dyaml/test/compare.d @@ -0,0 +1,51 @@ + +// Copyright Ferdinand Majerech 2011. +// 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.compare; + +@safe unittest +{ + import dyaml : Loader; + import dyaml.test.common : assertNodesEqual, compareEvents, run; + + /** + Test parser by comparing output from parsing two equivalent YAML files. + + Params: + dataFilename = YAML file to parse. + canonicalFilename = Another file to parse, in canonical YAML format. + */ + static void testParser(string dataFilename, string canonicalFilename) @safe + { + auto dataEvents = Loader.fromFile(dataFilename).parse(); + auto canonicalEvents = Loader.fromFile(canonicalFilename).parse(); + + //BUG: the return value isn't checked! This test currently fails... + compareEvents(dataEvents, canonicalEvents); + } + + /** + Test loader by comparing output from loading two equivalent YAML files. + + Params: + dataFilename = YAML file to load. + canonicalFilename = Another file to load, in canonical YAML format. + */ + static void testLoader(string dataFilename, string canonicalFilename) @safe + { + import std.array : array; + auto data = Loader.fromFile(dataFilename).array; + auto canonical = Loader.fromFile(canonicalFilename).array; + + assert(data.length == canonical.length, "Unequal node count"); + foreach (n; 0 .. data.length) + { + assertNodesEqual(data[n], canonical[n]); + } + } + run(&testParser, ["data", "canonical"]); + run(&testLoader, ["data", "canonical"], ["test_loader_skip"]); +} diff --git a/src/ext_depends/D-YAML/source/dyaml/test/constructor.d b/src/ext_depends/D-YAML/source/dyaml/test/constructor.d new file mode 100644 index 0000000..aeb8653 --- /dev/null +++ b/src/ext_depends/D-YAML/source/dyaml/test/constructor.d @@ -0,0 +1,957 @@ + +// Copyright Ferdinand Majerech 2011. +// 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.constructor; + + +version(unittest) +{ + +import std.conv; +import std.datetime; +import std.exception; +import std.path; +import std.string; +import std.typecons; + +import dyaml : Loader, Node, YAMLNull; + +///Expected results of loading test inputs. +Node[][string] expected; + +///Initialize expected. +static this() @safe +{ + expected["aliases-cdumper-bug"] = constructAliasesCDumperBug(); + expected["construct-binary"] = constructBinary(); + expected["construct-bool"] = constructBool(); + expected["construct-custom"] = constructCustom(); + expected["construct-float"] = constructFloat(); + expected["construct-int"] = constructInt(); + expected["construct-map"] = constructMap(); + expected["construct-merge"] = constructMerge(); + expected["construct-null"] = constructNull(); + expected["construct-omap"] = constructOMap(); + expected["construct-pairs"] = constructPairs(); + expected["construct-seq"] = constructSeq(); + expected["construct-set"] = constructSet(); + expected["construct-str-ascii"] = constructStrASCII(); + expected["construct-str"] = constructStr(); + expected["construct-str-utf8"] = constructStrUTF8(); + expected["construct-timestamp"] = constructTimestamp(); + expected["construct-value"] = constructValue(); + expected["duplicate-merge-key"] = duplicateMergeKey(); + expected["float-representer-2.3-bug"] = floatRepresenterBug(); + expected["invalid-single-quote-bug"] = invalidSingleQuoteBug(); + expected["more-floats"] = moreFloats(); + expected["negative-float-bug"] = negativeFloatBug(); + expected["single-dot-is-not-float-bug"] = singleDotFloatBug(); + expected["timestamp-bugs"] = timestampBugs(); + expected["utf16be"] = utf16be(); + expected["utf16le"] = utf16le(); + expected["utf8"] = utf8(); + expected["utf8-implicit"] = utf8implicit(); +} + +///Construct a pair of nodes with specified values. +Node.Pair pair(A, B)(A a, B b) +{ + return Node.Pair(a,b); +} + +///Test cases: + +Node[] constructAliasesCDumperBug() @safe +{ + return [ + Node( + [ + Node("today", "tag:yaml.org,2002:str"), + Node("today", "tag:yaml.org,2002:str") + ], + "tag:yaml.org,2002:seq") + ]; +} + +Node[] constructBinary() @safe +{ + auto canonical = "GIF89a\x0c\x00\x0c\x00\x84\x00\x00\xff\xff\xf7\xf5\xf5\xee\xe9\xe9\xe5fff\x00\x00\x00\xe7\xe7\xe7^^^\xf3\xf3\xed\x8e\x8e\x8e\xe0\xe0\xe0\x9f\x9f\x9f\x93\x93\x93\xa7\xa7\xa7\x9e\x9e\x9eiiiccc\xa3\xa3\xa3\x84\x84\x84\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9!\xfe\x0eMade with GIMP\x00,\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x05, \x8e\x810\x9e\xe3@\x14\xe8i\x10\xc4\xd1\x8a\x08\x1c\xcf\x80M$z\xef\xff0\x85p\xb8\xb01f\r\x1b\xce\x01\xc3\x01\x1e\x10' \x82\n\x01\x00;".representation.dup; + auto generic = "GIF89a\x0c\x00\x0c\x00\x84\x00\x00\xff\xff\xf7\xf5\xf5\xee\xe9\xe9\xe5fff\x00\x00\x00\xe7\xe7\xe7^^^\xf3\xf3\xed\x8e\x8e\x8e\xe0\xe0\xe0\x9f\x9f\x9f\x93\x93\x93\xa7\xa7\xa7\x9e\x9e\x9eiiiccc\xa3\xa3\xa3\x84\x84\x84\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9!\xfe\x0eMade with GIMP\x00,\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x05, \x8e\x810\x9e\xe3@\x14\xe8i\x10\xc4\xd1\x8a\x08\x1c\xcf\x80M$z\xef\xff0\x85p\xb8\xb01f\r\x1b\xce\x01\xc3\x01\x1e\x10' \x82\n\x01\x00;".representation.dup; + auto description = "The binary value above is a tiny arrow encoded as a gif image."; + + return [ + Node( + [ + pair( + Node("canonical", "tag:yaml.org,2002:str"), + Node(canonical, "tag:yaml.org,2002:binary") + ), + pair( + Node("generic", "tag:yaml.org,2002:str"), + Node(generic, "tag:yaml.org,2002:binary") + ), + pair( + Node("description", "tag:yaml.org,2002:str"), + Node(description, "tag:yaml.org,2002:str") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructBool() @safe +{ + const(bool) a = true; + immutable(bool) b = true; + const bool aa = true; + immutable bool bb = true; + return [ + Node( + [ + pair( + Node("canonical", "tag:yaml.org,2002:str"), + Node(true, "tag:yaml.org,2002:bool") + ), + pair( + Node("answer", "tag:yaml.org,2002:str"), + Node(false, "tag:yaml.org,2002:bool") + ), + pair( + Node("logical", "tag:yaml.org,2002:str"), + Node(true, "tag:yaml.org,2002:bool") + ), + pair( + Node("option", "tag:yaml.org,2002:str"), + Node(true, "tag:yaml.org,2002:bool") + ), + pair( + Node("constbool", "tag:yaml.org,2002:str"), + Node(a, "tag:yaml.org,2002:bool") + ), + pair( + Node("imutbool", "tag:yaml.org,2002:str"), + Node(b, "tag:yaml.org,2002:bool") + ), + pair( + Node("const_bool", "tag:yaml.org,2002:str"), + Node(aa, "tag:yaml.org,2002:bool") + ), + pair( + Node("imut_bool", "tag:yaml.org,2002:str"), + Node(bb, "tag:yaml.org,2002:bool") + ), + pair( + Node("but", "tag:yaml.org,2002:str"), + Node( + [ + pair( + Node("y", "tag:yaml.org,2002:str"), + Node("is a string", "tag:yaml.org,2002:str") + ), + pair( + Node("n", "tag:yaml.org,2002:str"), + Node("is a string", "tag:yaml.org,2002:str") + ) + ], + "tag:yaml.org,2002:map") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructCustom() @safe +{ + return [ + Node( + [ + Node(new TestClass(1, 2, 3)), + Node(TestStruct(10)) + ], + "tag:yaml.org,2002:seq") + ]; +} + +Node[] constructFloat() @safe +{ + return [ + Node( + [ + pair( + Node("canonical", "tag:yaml.org,2002:str"), + Node(685230.15L, "tag:yaml.org,2002:float") + ), + pair( + Node("exponential", "tag:yaml.org,2002:str"), + Node(685230.15L, "tag:yaml.org,2002:float") + ), + pair( + Node("fixed", "tag:yaml.org,2002:str"), + Node(685230.15L, "tag:yaml.org,2002:float") + ), + pair( + Node("sexagesimal", "tag:yaml.org,2002:str"), + Node(685230.15L, "tag:yaml.org,2002:float") + ), + pair( + Node("negative infinity", "tag:yaml.org,2002:str"), + Node(-real.infinity, "tag:yaml.org,2002:float") + ), + pair( + Node("not a number", "tag:yaml.org,2002:str"), + Node(real.nan, "tag:yaml.org,2002:float") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructInt() @safe +{ + return [ + Node( + [ + pair( + Node("canonical", "tag:yaml.org,2002:str"), + Node(685230L, "tag:yaml.org,2002:int") + ), + pair( + Node("decimal", "tag:yaml.org,2002:str"), + Node(685230L, "tag:yaml.org,2002:int") + ), + pair( + Node("octal", "tag:yaml.org,2002:str"), + Node(685230L, "tag:yaml.org,2002:int") + ), + pair( + Node("hexadecimal", "tag:yaml.org,2002:str"), + Node(685230L, "tag:yaml.org,2002:int") + ), + pair( + Node("binary", "tag:yaml.org,2002:str"), + Node(685230L, "tag:yaml.org,2002:int") + ), + pair( + Node("sexagesimal", "tag:yaml.org,2002:str"), + Node(685230L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructMap() @safe +{ + return [ + Node( + [ + pair( + Node("Block style", "tag:yaml.org,2002:str"), + Node( + [ + pair( + Node("Clark", "tag:yaml.org,2002:str"), + Node("Evans", "tag:yaml.org,2002:str") + ), + pair( + Node("Brian", "tag:yaml.org,2002:str"), + Node("Ingerson", "tag:yaml.org,2002:str") + ), + pair( + Node("Oren", "tag:yaml.org,2002:str"), + Node("Ben-Kiki", "tag:yaml.org,2002:str") + ) + ], + "tag:yaml.org,2002:map") + ), + pair( + Node("Flow style", "tag:yaml.org,2002:str"), + Node( + [ + pair( + Node("Clark", "tag:yaml.org,2002:str"), + Node("Evans", "tag:yaml.org,2002:str") + ), + pair( + Node("Brian", "tag:yaml.org,2002:str"), + Node("Ingerson", "tag:yaml.org,2002:str") + ), + pair( + Node("Oren", "tag:yaml.org,2002:str"), + Node("Ben-Kiki", "tag:yaml.org,2002:str") + ) + ], + "tag:yaml.org,2002:map") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructMerge() @safe +{ + return [ + Node( + [ + Node( + [ + pair( + Node("x", "tag:yaml.org,2002:str"), + Node(1L, "tag:yaml.org,2002:int") + ), + pair( + Node("y", "tag:yaml.org,2002:str"), + Node(2L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:map"), + Node( + [ + pair( + Node("x", "tag:yaml.org,2002:str"), + Node(0L, "tag:yaml.org,2002:int") + ), + pair( + Node("y", "tag:yaml.org,2002:str"), + Node(2L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:map"), + Node( + [ + pair( + Node("r", "tag:yaml.org,2002:str"), + Node(10L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:map"), + Node( + [ + pair( + Node("r", "tag:yaml.org,2002:str"), + Node(1L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:map"), + Node( + [ + pair( + Node("x", "tag:yaml.org,2002:str"), + Node(1L, "tag:yaml.org,2002:int") + ), + pair( + Node("y", "tag:yaml.org,2002:str"), + Node(2L, "tag:yaml.org,2002:int") + ), + pair( + Node("r", "tag:yaml.org,2002:str"), + Node(10L, "tag:yaml.org,2002:int") + ), + pair( + Node("label", "tag:yaml.org,2002:str"), + Node("center/big", "tag:yaml.org,2002:str") + ) + ], + "tag:yaml.org,2002:map"), + Node( + [ + pair( + Node("r", "tag:yaml.org,2002:str"), + Node(10L, "tag:yaml.org,2002:int") + ), + pair( + Node("label", "tag:yaml.org,2002:str"), + Node("center/big", "tag:yaml.org,2002:str") + ), + pair( + Node("x", "tag:yaml.org,2002:str"), + Node(1L, "tag:yaml.org,2002:int") + ), + pair( + Node("y", "tag:yaml.org,2002:str"), + Node(2L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:map"), + Node( + [ + pair( + Node("label", "tag:yaml.org,2002:str"), + Node("center/big", "tag:yaml.org,2002:str") + ), + pair( + Node("x", "tag:yaml.org,2002:str"), + Node(1L, "tag:yaml.org,2002:int") + ), + pair( + Node("y", "tag:yaml.org,2002:str"), + Node(2L, "tag:yaml.org,2002:int") + ), + pair( + Node("r", "tag:yaml.org,2002:str"), + Node(10L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:map"), + Node( + [ + pair( + Node("x", "tag:yaml.org,2002:str"), + Node(1L, "tag:yaml.org,2002:int") + ), + pair( + Node("label", "tag:yaml.org,2002:str"), + Node("center/big", "tag:yaml.org,2002:str") + ), + pair( + Node("r", "tag:yaml.org,2002:str"), + Node(10L, "tag:yaml.org,2002:int") + ), + pair( + Node("y", "tag:yaml.org,2002:str"), + Node(2L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:map") + ], + "tag:yaml.org,2002:seq") + ]; +} + +Node[] constructNull() @safe +{ + return [ + Node(YAMLNull(), "tag:yaml.org,2002:null"), + Node( + [ + pair( + Node("empty", "tag:yaml.org,2002:str"), + Node(YAMLNull(), "tag:yaml.org,2002:null") + ), + pair( + Node("canonical", "tag:yaml.org,2002:str"), + Node(YAMLNull(), "tag:yaml.org,2002:null") + ), + pair( + Node("english", "tag:yaml.org,2002:str"), + Node(YAMLNull(), "tag:yaml.org,2002:null") + ), + pair( + Node(YAMLNull(), "tag:yaml.org,2002:null"), + Node("null key", "tag:yaml.org,2002:str") + ) + ], + "tag:yaml.org,2002:map"), + Node( + [ + pair( + Node("sparse", "tag:yaml.org,2002:str"), + Node( + [ + Node(YAMLNull(), "tag:yaml.org,2002:null"), + Node("2nd entry", "tag:yaml.org,2002:str"), + Node(YAMLNull(), "tag:yaml.org,2002:null"), + Node("4th entry", "tag:yaml.org,2002:str"), + Node(YAMLNull(), "tag:yaml.org,2002:null") + ], + "tag:yaml.org,2002:seq") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructOMap() @safe +{ + return [ + Node( + [ + pair( + Node("Bestiary", "tag:yaml.org,2002:str"), + Node( + [ + pair( + Node("aardvark", "tag:yaml.org,2002:str"), + Node("African pig-like ant eater. Ugly.", "tag:yaml.org,2002:str") + ), + pair( + Node("anteater", "tag:yaml.org,2002:str"), + Node("South-American ant eater. Two species.", "tag:yaml.org,2002:str") + ), + pair( + Node("anaconda", "tag:yaml.org,2002:str"), + Node("South-American constrictor snake. Scaly.", "tag:yaml.org,2002:str") + ) + ], + "tag:yaml.org,2002:omap") + ), + pair( + Node("Numbers", "tag:yaml.org,2002:str"), + Node( + [ + pair( + Node("one", "tag:yaml.org,2002:str"), + Node(1L, "tag:yaml.org,2002:int") + ), + pair( + Node("two", "tag:yaml.org,2002:str"), + Node(2L, "tag:yaml.org,2002:int") + ), + pair( + Node("three", "tag:yaml.org,2002:str"), + Node(3L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:omap") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructPairs() @safe +{ + return [ + Node( + [ + pair( + Node("Block tasks", "tag:yaml.org,2002:str"), + Node( + [ + pair(Node("meeting", "tag:yaml.org,2002:str"), Node("with team.", "tag:yaml.org,2002:str")), + pair(Node("meeting", "tag:yaml.org,2002:str"), Node("with boss.", "tag:yaml.org,2002:str")), + pair(Node("break", "tag:yaml.org,2002:str"), Node("lunch.", "tag:yaml.org,2002:str")), + pair(Node("meeting", "tag:yaml.org,2002:str"), Node("with client.", "tag:yaml.org,2002:str")) + ], + "tag:yaml.org,2002:pairs") + ), + pair( + Node("Flow tasks", "tag:yaml.org,2002:str"), + Node( + [ + pair(Node("meeting", "tag:yaml.org,2002:str"), Node("with team", "tag:yaml.org,2002:str")), + pair(Node("meeting", "tag:yaml.org,2002:str"), Node("with boss", "tag:yaml.org,2002:str")) + ], + "tag:yaml.org,2002:pairs") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructSeq() @safe +{ + return [ + Node( + [ + pair( + Node("Block style", "tag:yaml.org,2002:str"), + Node([ + Node("Mercury", "tag:yaml.org,2002:str"), + Node("Venus", "tag:yaml.org,2002:str"), + Node("Earth", "tag:yaml.org,2002:str"), + Node("Mars", "tag:yaml.org,2002:str"), + Node("Jupiter", "tag:yaml.org,2002:str"), + Node("Saturn", "tag:yaml.org,2002:str"), + Node("Uranus", "tag:yaml.org,2002:str"), + Node("Neptune", "tag:yaml.org,2002:str"), + Node("Pluto", "tag:yaml.org,2002:str") + ], "tag:yaml.org,2002:seq") + ), + pair( + Node("Flow style", "tag:yaml.org,2002:str"), + Node([ + Node("Mercury", "tag:yaml.org,2002:str"), + Node("Venus", "tag:yaml.org,2002:str"), + Node("Earth", "tag:yaml.org,2002:str"), + Node("Mars", "tag:yaml.org,2002:str"), + Node("Jupiter", "tag:yaml.org,2002:str"), + Node("Saturn", "tag:yaml.org,2002:str"), + Node("Uranus", "tag:yaml.org,2002:str"), + Node("Neptune", "tag:yaml.org,2002:str"), + Node("Pluto", "tag:yaml.org,2002:str") + ], "tag:yaml.org,2002:seq") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructSet() @safe +{ + return [ + Node( + [ + pair( + Node("baseball players", "tag:yaml.org,2002:str"), + Node( + [ + Node("Mark McGwire", "tag:yaml.org,2002:str"), + Node("Sammy Sosa", "tag:yaml.org,2002:str"), + Node("Ken Griffey", "tag:yaml.org,2002:str") + ], + "tag:yaml.org,2002:set") + ), + pair( + Node("baseball teams", "tag:yaml.org,2002:str"), + Node( + [ + Node("Boston Red Sox", "tag:yaml.org,2002:str"), + Node("Detroit Tigers", "tag:yaml.org,2002:str"), + Node("New York Yankees", "tag:yaml.org,2002:str") + ], + "tag:yaml.org,2002:set") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructStrASCII() @safe +{ + return [ + Node("ascii string", "tag:yaml.org,2002:str") + ]; +} + +Node[] constructStr() @safe +{ + return [ + Node( + [ + pair( + Node("string", "tag:yaml.org,2002:str"), + Node("abcd", "tag:yaml.org,2002:str") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructStrUTF8() @safe +{ + return [ + Node("\u042d\u0442\u043e \u0443\u043d\u0438\u043a\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430", "tag:yaml.org,2002:str") + ]; +} + +Node[] constructTimestamp() @safe +{ + return [ + Node( + [ + pair( + Node("canonical", "tag:yaml.org,2002:str"), + Node(SysTime(DateTime(2001, 12, 15, 2, 59, 43), 1000000.dur!"hnsecs", UTC()), "tag:yaml.org,2002:timestamp") + ), + pair( + Node("valid iso8601", "tag:yaml.org,2002:str"), + Node(SysTime(DateTime(2001, 12, 15, 2, 59, 43), 1000000.dur!"hnsecs", UTC()), "tag:yaml.org,2002:timestamp") + ), + pair( + Node("space separated", "tag:yaml.org,2002:str"), + Node(SysTime(DateTime(2001, 12, 15, 2, 59, 43), 1000000.dur!"hnsecs", UTC()), "tag:yaml.org,2002:timestamp") + ), + pair( + Node("no time zone (Z)", "tag:yaml.org,2002:str"), + Node(SysTime(DateTime(2001, 12, 15, 2, 59, 43), 1000000.dur!"hnsecs", UTC()), "tag:yaml.org,2002:timestamp") + ), + pair( + Node("date (00:00:00Z)", "tag:yaml.org,2002:str"), + Node(SysTime(DateTime(2002, 12, 14), UTC()), "tag:yaml.org,2002:timestamp") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] constructValue() @safe +{ + return [ + Node( + [ + pair( + Node("link with", "tag:yaml.org,2002:str"), + Node( + [ + Node("library1.dll", "tag:yaml.org,2002:str"), + Node("library2.dll", "tag:yaml.org,2002:str") + ], + "tag:yaml.org,2002:seq") + ) + ], + "tag:yaml.org,2002:map"), + Node( + [ + pair( + Node("link with", "tag:yaml.org,2002:str"), + Node( + [ + Node( + [ + pair( + Node("=", "tag:yaml.org,2002:value"), + Node("library1.dll", "tag:yaml.org,2002:str") + ), + pair( + Node("version", "tag:yaml.org,2002:str"), + Node(1.2L, "tag:yaml.org,2002:float") + ) + ], + "tag:yaml.org,2002:map"), + Node( + [ + pair( + Node("=", "tag:yaml.org,2002:value"), + Node("library2.dll", "tag:yaml.org,2002:str") + ), + pair( + Node("version", "tag:yaml.org,2002:str"), + Node(2.3L, "tag:yaml.org,2002:float") + ) + ], + "tag:yaml.org,2002:map") + ], + "tag:yaml.org,2002:seq") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] duplicateMergeKey() @safe +{ + return [ + Node( + [ + pair( + Node("foo", "tag:yaml.org,2002:str"), + Node("bar", "tag:yaml.org,2002:str") + ), + pair( + Node("x", "tag:yaml.org,2002:str"), + Node(1L, "tag:yaml.org,2002:int") + ), + pair( + Node("y", "tag:yaml.org,2002:str"), + Node(2L, "tag:yaml.org,2002:int") + ), + pair( + Node("z", "tag:yaml.org,2002:str"), + Node(3L, "tag:yaml.org,2002:int") + ), + pair( + Node("t", "tag:yaml.org,2002:str"), + Node(4L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] floatRepresenterBug() @safe +{ + return [ + Node( + [ + pair( + Node(1.0L, "tag:yaml.org,2002:float"), + Node(1L, "tag:yaml.org,2002:int") + ), + pair( + Node(real.infinity, "tag:yaml.org,2002:float"), + Node(10L, "tag:yaml.org,2002:int") + ), + pair( + Node(-real.infinity, "tag:yaml.org,2002:float"), + Node(-10L, "tag:yaml.org,2002:int") + ), + pair( + Node(real.nan, "tag:yaml.org,2002:float"), + Node(100L, "tag:yaml.org,2002:int") + ) + ], + "tag:yaml.org,2002:map") + ]; +} + +Node[] invalidSingleQuoteBug() @safe +{ + return [ + Node( + [ + Node("foo \'bar\'", "tag:yaml.org,2002:str"), + Node("foo\n\'bar\'", "tag:yaml.org,2002:str") + ], + "tag:yaml.org,2002:seq") + ]; +} + +Node[] moreFloats() @safe +{ + return [ + Node( + [ + Node(0.0L, "tag:yaml.org,2002:float"), + Node(1.0L, "tag:yaml.org,2002:float"), + Node(-1.0L, "tag:yaml.org,2002:float"), + Node(real.infinity, "tag:yaml.org,2002:float"), + Node(-real.infinity, "tag:yaml.org,2002:float"), + Node(real.nan, "tag:yaml.org,2002:float"), + Node(real.nan, "tag:yaml.org,2002:float") + ], + "tag:yaml.org,2002:seq") + ]; +} + +Node[] negativeFloatBug() @safe +{ + return [ + Node(-1.0L, "tag:yaml.org,2002:float") + ]; +} + +Node[] singleDotFloatBug() @safe +{ + return [ + Node(".", "tag:yaml.org,2002:str") + ]; +} + +Node[] timestampBugs() @safe +{ + return [ + Node( + [ + Node(SysTime(DateTime(2001, 12, 15, 3, 29, 43), 1000000.dur!"hnsecs", UTC()), "tag:yaml.org,2002:timestamp"), + Node(SysTime(DateTime(2001, 12, 14, 16, 29, 43), 1000000.dur!"hnsecs", UTC()), "tag:yaml.org,2002:timestamp"), + Node(SysTime(DateTime(2001, 12, 14, 21, 59, 43), 10100.dur!"hnsecs", UTC()), "tag:yaml.org,2002:timestamp"), + Node(SysTime(DateTime(2001, 12, 14, 21, 59, 43), new immutable SimpleTimeZone(60.dur!"minutes")), "tag:yaml.org,2002:timestamp"), + Node(SysTime(DateTime(2001, 12, 14, 21, 59, 43), new immutable SimpleTimeZone(-90.dur!"minutes")), "tag:yaml.org,2002:timestamp"), + Node(SysTime(DateTime(2005, 7, 8, 17, 35, 4), 5176000.dur!"hnsecs", UTC()), "tag:yaml.org,2002:timestamp") + ], + "tag:yaml.org,2002:seq") + ]; +} + +Node[] utf16be() @safe +{ + return [ + Node("UTF-16-BE", "tag:yaml.org,2002:str") + ]; +} + +Node[] utf16le() @safe +{ + return [ + Node("UTF-16-LE", "tag:yaml.org,2002:str") + ]; +} + +Node[] utf8() @safe +{ + return [ + Node("UTF-8", "tag:yaml.org,2002:str") + ]; +} + +Node[] utf8implicit() @safe +{ + return [ + Node("implicit UTF-8", "tag:yaml.org,2002:str") + ]; +} + +///Testing custom YAML class type. +class TestClass +{ + int x, y, z; + + this(int x, int y, int z) @safe + { + this.x = x; + this.y = y; + this.z = z; + } + + Node opCast(T: Node)() @safe + { + return Node( + [ + Node.Pair( + Node("x", "tag:yaml.org,2002:str"), + Node(x, "tag:yaml.org,2002:int") + ), + Node.Pair( + Node("y", "tag:yaml.org,2002:str"), + Node(y, "tag:yaml.org,2002:int") + ), + Node.Pair( + Node("z", "tag:yaml.org,2002:str"), + Node(z, "tag:yaml.org,2002:int") + ) + ], + "!tag1"); + } +} + +///Testing custom YAML struct type. +struct TestStruct +{ + int value; + + this (int x) @safe + { + value = x; + } + + ///Constructor function for TestStruct. + this(ref Node node) @safe + { + value = node.as!string.to!int; + } + + ///Representer function for TestStruct. + Node opCast(T: Node)() @safe + { + return Node(value.to!string, "!tag2"); + } +} + +} // version(unittest) + + +@safe unittest +{ + import dyaml.test.common : assertNodesEqual, run; + /** + Constructor unittest. + + Params: + dataFilename = File name to read from. + codeDummy = Dummy .code filename, used to determine that + .data file with the same name should be used in this test. + */ + static void testConstructor(string dataFilename, string codeDummy) @safe + { + string base = dataFilename.baseName.stripExtension; + assert((base in expected) !is null, "Unimplemented constructor test: " ~ base); + + auto loader = Loader.fromFile(dataFilename); + + Node[] exp = expected[base]; + + //Compare with expected results document by document. + size_t i; + foreach (node; loader) + { + assertNodesEqual(node, exp[i]); + ++i; + } + assert(i == exp.length); + } + run(&testConstructor, ["data", "code"]); +} diff --git a/src/ext_depends/D-YAML/source/dyaml/test/emitter.d b/src/ext_depends/D-YAML/source/dyaml/test/emitter.d new file mode 100644 index 0000000..293f236 --- /dev/null +++ b/src/ext_depends/D-YAML/source/dyaml/test/emitter.d @@ -0,0 +1,132 @@ + +// 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.emitter; + +@safe unittest +{ + import std.array : Appender; + import std.range : ElementType, isInputRange; + + import dyaml : CollectionStyle, LineBreak, Loader, Mark, ScalarStyle; + import dyaml.emitter : Emitter; + import dyaml.event : Event, EventID, mappingStartEvent, scalarEvent, sequenceStartEvent; + import dyaml.test.common : assertEventsEqual, run; + + // Try to emit an event range. + static void emitTestCommon(T)(ref Appender!string emitStream, T events, bool canonical = false) @safe + if (isInputRange!T && is(ElementType!T == Event)) + { + auto emitter = Emitter!(typeof(emitStream), char)(emitStream, canonical, 2, 80, LineBreak.unix); + foreach (ref event; events) + { + emitter.emit(event); + } + } + /** + Test emitter by getting events from parsing a file, emitting them, parsing + the emitted result and comparing events from parsing the emitted result with + originally parsed events. + + Params: + dataFilename = YAML file to parse. + canonicalFilename = Canonical YAML file used as dummy to determine + which data files to load. + */ + static void testEmitterOnData(string dataFilename, string canonicalFilename) @safe + { + //Must exist due to Anchor, Tags reference counts. + auto loader = Loader.fromFile(dataFilename); + auto events = loader.parse(); + auto emitStream = Appender!string(); + emitTestCommon(emitStream, events); + + auto loader2 = Loader.fromString(emitStream.data); + loader2.name = "TEST"; + auto newEvents = loader2.parse(); + assertEventsEqual(events, newEvents); + } + /** + Test emitter by getting events from parsing a canonical YAML file, emitting + them both in canonical and normal format, parsing the emitted results and + comparing events from parsing the emitted result with originally parsed events. + + Params: canonicalFilename = Canonical YAML file to parse. + */ + static void testEmitterOnCanonical(string canonicalFilename) @safe + { + //Must exist due to Anchor, Tags reference counts. + auto loader = Loader.fromFile(canonicalFilename); + auto events = loader.parse(); + foreach (canonical; [false, true]) + { + auto emitStream = Appender!string(); + emitTestCommon(emitStream, events, canonical); + + auto loader2 = Loader.fromString(emitStream.data); + loader2.name = "TEST"; + auto newEvents = loader2.parse(); + assertEventsEqual(events, newEvents); + } + } + /** + Test emitter by getting events from parsing a file, emitting them with all + possible scalar and collection styles, parsing the emitted results and + comparing events from parsing the emitted result with originally parsed events. + + Params: + dataFilename = YAML file to parse. + canonicalFilename = Canonical YAML file used as dummy to determine + which data files to load. + */ + static void testEmitterStyles(string dataFilename, string canonicalFilename) @safe + { + foreach (filename; [dataFilename, canonicalFilename]) + { + //must exist due to Anchor, Tags reference counts + auto loader = Loader.fromFile(canonicalFilename); + auto events = loader.parse(); + foreach (flowStyle; [CollectionStyle.block, CollectionStyle.flow]) + { + foreach (style; [ScalarStyle.literal, ScalarStyle.folded, + ScalarStyle.doubleQuoted, ScalarStyle.singleQuoted, + ScalarStyle.plain]) + { + Event[] styledEvents; + foreach (event; events) + { + if (event.id == EventID.scalar) + { + event = scalarEvent(Mark(), Mark(), event.anchor, event.tag, + event.implicit, + event.value, style); + } + else if (event.id == EventID.sequenceStart) + { + event = sequenceStartEvent(Mark(), Mark(), event.anchor, + event.tag, event.implicit, flowStyle); + } + else if (event.id == EventID.mappingStart) + { + event = mappingStartEvent(Mark(), Mark(), event.anchor, + event.tag, event.implicit, flowStyle); + } + styledEvents ~= event; + } + auto emitStream = Appender!string(); + emitTestCommon(emitStream, styledEvents); + auto loader2 = Loader.fromString(emitStream.data); + loader2.name = "TEST"; + auto newEvents = loader2.parse(); + assertEventsEqual(events, newEvents); + } + } + } + } + run(&testEmitterOnData, ["data", "canonical"]); + run(&testEmitterOnCanonical, ["canonical"]); + run(&testEmitterStyles, ["data", "canonical"]); +} diff --git a/src/ext_depends/D-YAML/source/dyaml/test/errors.d b/src/ext_depends/D-YAML/source/dyaml/test/errors.d new file mode 100644 index 0000000..43b019c --- /dev/null +++ b/src/ext_depends/D-YAML/source/dyaml/test/errors.d @@ -0,0 +1,64 @@ + +// 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.errors; + +@safe unittest +{ + import std.array : array; + import std.exception : assertThrown; + + import dyaml : Loader; + import dyaml.test.common : run; + + /** + Loader error unittest from file stream. + + Params: errorFilename = File name to read from. + */ + static void testLoaderError(string errorFilename) @safe + { + assertThrown(Loader.fromFile(errorFilename).array, + __FUNCTION__ ~ "(" ~ errorFilename ~ ") Expected an exception"); + } + + /** + Loader error unittest from string. + + Params: errorFilename = File name to read from. + */ + static void testLoaderErrorString(string errorFilename) @safe + { + assertThrown(Loader.fromFile(errorFilename).array, + __FUNCTION__ ~ "(" ~ errorFilename ~ ") Expected an exception"); + } + + /** + Loader error unittest from filename. + + Params: errorFilename = File name to read from. + */ + static void testLoaderErrorFilename(string errorFilename) @safe + { + assertThrown(Loader.fromFile(errorFilename).array, + __FUNCTION__ ~ "(" ~ errorFilename ~ ") Expected an exception"); + } + + /** + Loader error unittest loading a single document from a file. + + Params: errorFilename = File name to read from. + */ + static void testLoaderErrorSingle(string errorFilename) @safe + { + assertThrown(Loader.fromFile(errorFilename).load(), + __FUNCTION__ ~ "(" ~ errorFilename ~ ") Expected an exception"); + } + run(&testLoaderError, ["loader-error"]); + run(&testLoaderErrorString, ["loader-error"]); + run(&testLoaderErrorFilename, ["loader-error"]); + run(&testLoaderErrorSingle, ["single-loader-error"]); +} 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"]); +} diff --git a/src/ext_depends/D-YAML/source/dyaml/test/reader.d b/src/ext_depends/D-YAML/source/dyaml/test/reader.d new file mode 100644 index 0000000..c20df6f --- /dev/null +++ b/src/ext_depends/D-YAML/source/dyaml/test/reader.d @@ -0,0 +1,37 @@ + +// Copyright Ferdinand Majerech 2011. +// 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.reader; + +@safe unittest +{ + import std.exception :assertThrown; + + import dyaml.test.common : readData, run; + import dyaml.reader : Reader, ReaderException; + + /** + Try reading entire file through Reader, expecting an error (the file is invalid). + + Params: data = Stream to read. + */ + static void runReader(ubyte[] fileData) @safe + { + auto reader = new Reader(fileData); + while(reader.peek() != '\0') { reader.forward(); } + } + + /** + Stream error unittest. Tries to read invalid input files, expecting errors. + + Params: errorFilename = File name to read from. + */ + static void testStreamError(string errorFilename) @safe + { + assertThrown!ReaderException(runReader(readData(errorFilename))); + } + run(&testStreamError, ["stream-error"]); +} diff --git a/src/ext_depends/D-YAML/source/dyaml/test/representer.d b/src/ext_depends/D-YAML/source/dyaml/test/representer.d new file mode 100644 index 0000000..4a1ae67 --- /dev/null +++ b/src/ext_depends/D-YAML/source/dyaml/test/representer.d @@ -0,0 +1,54 @@ + +// Copyright Ferdinand Majerech 2011. +// 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.representer; + +@safe unittest +{ + import std.array : Appender, array; + import std.meta : AliasSeq; + import std.path : baseName, stripExtension; + import std.utf : toUTF8; + + import dyaml : dumper, Loader, Node; + import dyaml.test.common : assertNodesEqual, run; + import dyaml.test.constructor : expected; + + /** + Representer unittest. Dumps nodes, then loads them again. + + Params: + baseName = Nodes in dyaml.test.constructor.expected for roundtripping. + */ + static void testRepresenterTypes(string baseName) @safe + { + assert((baseName in expected) !is null, "Unimplemented representer test: " ~ baseName); + + Node[] expectedNodes = expected[baseName]; + foreach (encoding; AliasSeq!(char, wchar, dchar)) + { + auto emitStream = new Appender!(immutable(encoding)[]); + auto dumper = dumper(); + dumper.dump!encoding(emitStream, expectedNodes); + + immutable output = emitStream.data; + + auto loader = Loader.fromString(emitStream.data.toUTF8); + loader.name = "TEST"; + const readNodes = loader.array; + + assert(expectedNodes.length == readNodes.length); + foreach (n; 0 .. expectedNodes.length) + { + assertNodesEqual(expectedNodes[n], readNodes[n]); + } + } + } + foreach (key, _; expected) + { + testRepresenterTypes(key); + } +} diff --git a/src/ext_depends/D-YAML/source/dyaml/test/resolver.d b/src/ext_depends/D-YAML/source/dyaml/test/resolver.d new file mode 100644 index 0000000..ea93720 --- /dev/null +++ b/src/ext_depends/D-YAML/source/dyaml/test/resolver.d @@ -0,0 +1,39 @@ + +// Copyright Ferdinand Majerech 2011. +// 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.resolver; + +@safe unittest +{ + import std.conv : text; + import std.file : readText; + import std.string : strip; + + import dyaml : Loader, Node, NodeID; + import dyaml.test.common : run; + + + /** + Implicit tag resolution unittest. + + Params: + dataFilename = File with unittest data. + detectFilename = Dummy filename used to specify which data filenames to use. + */ + static void testImplicitResolver(string dataFilename, string detectFilename) @safe + { + const correctTag = readText(detectFilename).strip(); + + auto node = Loader.fromFile(dataFilename).load(); + assert(node.nodeID == NodeID.sequence, text("Expected sequence when reading '", dataFilename, "', got ", node.nodeID)); + foreach (Node scalar; node) + { + assert(scalar.nodeID == NodeID.scalar, text("Expected sequence of scalars when reading '", dataFilename, "', got sequence of ", scalar.nodeID)); + assert(scalar.tag == correctTag, text("Expected tag '", correctTag, "' when reading '", dataFilename, "', got '", scalar.tag, "'")); + } + } + run(&testImplicitResolver, ["data", "detect"]); +} diff --git a/src/ext_depends/D-YAML/source/dyaml/test/tokens.d b/src/ext_depends/D-YAML/source/dyaml/test/tokens.d new file mode 100644 index 0000000..c099647 --- /dev/null +++ b/src/ext_depends/D-YAML/source/dyaml/test/tokens.d @@ -0,0 +1,93 @@ + +// Copyright Ferdinand Majerech 2011. +// 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.tokens; + +@safe unittest +{ + import std.array : split; + import std.conv : text; + import std.file : readText; + + import dyaml.test.common : run; + import dyaml.reader : Reader; + import dyaml.scanner : Scanner; + import dyaml.token : TokenID; + + // Read and scan a YAML doc, returning a range of tokens. + static auto scanTestCommon(string filename) @safe + { + ubyte[] yamlData = cast(ubyte[])readText(filename).dup; + return Scanner(new Reader(yamlData)); + } + + /** + Test tokens output by scanner. + + Params: + dataFilename = File to scan. + tokensFilename = File containing expected tokens. + */ + static void testTokens(string dataFilename, string tokensFilename) @safe + { + //representations of YAML tokens in tokens file. + auto replace = [ + TokenID.directive: "%", + TokenID.documentStart: "---", + TokenID.documentEnd: "...", + TokenID.alias_: "*", + TokenID.anchor: "&", + TokenID.tag: "!", + TokenID.scalar: "_", + TokenID.blockSequenceStart: "[[", + TokenID.blockMappingStart: "{{", + TokenID.blockEnd: "]}", + TokenID.flowSequenceStart: "[", + TokenID.flowSequenceEnd: "]", + TokenID.flowMappingStart: "{", + TokenID.flowMappingEnd: "}", + TokenID.blockEntry: ",", + TokenID.flowEntry: ",", + TokenID.key: "?", + TokenID.value: ":" + ]; + + string[] tokens; + string[] expectedTokens = readText(tokensFilename).split(); + + foreach (token; scanTestCommon(dataFilename)) + { + if (token.id != TokenID.streamStart && token.id != TokenID.streamEnd) + { + tokens ~= replace[token.id]; + } + } + + assert(tokens == expectedTokens, + text("In token test for '", tokensFilename, "', expected '", expectedTokens, "', got '", tokens, "'")); + } + + /** + Test scanner by scanning a file, expecting no errors. + + Params: + dataFilename = File to scan. + canonicalFilename = Another file to scan, in canonical YAML format. + */ + static void testScanner(string dataFilename, string canonicalFilename) @safe + { + foreach (filename; [dataFilename, canonicalFilename]) + { + string[] tokens; + foreach (token; scanTestCommon(filename)) + { + tokens ~= token.id.text; + } + } + } + run(&testTokens, ["data", "tokens"]); + run(&testScanner, ["data", "canonical"]); +} -- cgit v1.2.3