-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnested.d
52 lines (44 loc) · 1.5 KB
/
nested.d
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
module tests.nested;
import unit_threaded;
import cerealed;
struct Nested {
Nested[int] aa;
}
struct SomeStruct {
string[] str;
int[][] ints;
Nested[] nesteds;
}
void testEmptyNested() {
SomeStruct original, restored;
auto enc = Cerealiser();
enc ~= original;
auto dec = Decerealiser(enc.bytes);
restored = dec.value!(SomeStruct);
original.shouldEqual(restored);
}
void testNested() {
auto some = SomeStruct(["foo", "sunny"],
[[2, 4], [1, 3, 5]],
[Nested([7: Nested()])]);
auto enc = Cerealiser();
enc ~= some;
enc.bytes.shouldEqual([0, 2, 0, 3, 'f', 'o', 'o', 0, 5, 's', 'u', 'n', 'n', 'y',
0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 0, 4, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 5,
0, 1, 0, 1, 0, 0, 0, 7, 0, 0]);
auto dec = Decerealiser(enc.bytes);
dec.value!SomeStruct.shouldEqual(some);
}
void testNestedDynamic() {
SomeStruct[] some;
some ~= SomeStruct(["foo", "sunny"],
[[2, 4], [1, 3, 5]],
[Nested([7: Nested()])]);
auto enc = Cerealiser();
enc ~= some;
enc.bytes.shouldEqual([0, 1, 0, 2, 0, 3, 'f', 'o', 'o', 0, 5, 's', 'u', 'n', 'n', 'y',
0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 0, 4, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 5,
0, 1, 0, 1, 0, 0, 0, 7, 0, 0]);
auto dec = Decerealiser(enc.bytes);
dec.value!(SomeStruct[]).shouldEqual(some);
}