blob: 4a1ae67b14a396defc3542ecdd9ced826a967a98 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
}
}
|