annotate tests/Serializer.d @ 32:9df3b7a46a51 experimental

Updated the unit test with the latest changes.
author Jacob Carlborg <doob@me.com>
date Sun, 21 Nov 2010 18:51:05 +0100
parents bffcbc8c392b
children 4fea56a5849f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
2 /**
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
3 * Copyright: Copyright (c) 2010 Jacob Carlborg. All rights reserved.
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
4 * Authors: Jacob Carlborg
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
5 * Version: Initial created: Nov 5, 2010
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
6 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
7 */
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
8 module tests.Serializer;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
9
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
10 private:
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
11
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
12 import orange.serialization.Serializer;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
13 import orange.serialization.archives.XMLArchive;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
14 import orange.core.io;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
15 import orange.core.string;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
16
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
17 bool containsDefaultXmlContent (string source)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
18 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
19 return source.containsXmlHeader() &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
20 source.containsArchive() &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
21 source.containsXmlTag("data");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
22 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
23
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
24 bool containsXmlHeader (string source)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
25 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
26 return source.contains(`<?xml version="1.0" encoding="UTF-8"?>`);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
27 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
28
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
29 bool containsArchive (string source)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
30 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
31 return source.containsArchiveHeader() && source.contains("</archive>");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
32 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
33
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
34 bool containsArchiveHeader (string source)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
35 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
36 return source.contains(`<archive type="org.dsource.orange.xml" version="1.0.0">`);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
37 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
38
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
39 bool containsXmlTag (string source, string tag, bool simple = false)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
40 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
41 return source.containsXmlTag(tag, null, null, simple);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
43
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44 bool containsXmlTag (string source, string tag, string attributes, bool simple = false)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 return source.containsXmlTag(tag, attributes, null, simple);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
47 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
48
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
49 bool containsXmlTag (string source, string tag, string attributes, string content, bool simple = false)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
51 string pattern = '<' ~ tag;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
52
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
53 if (attributes.length > 0)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54 pattern ~= ' ' ~ attributes;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56 if (simple)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 return source.contains(pattern ~ "/>");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
59 if (content.length > 0)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
60 return source.contains(pattern ~ '>' ~ content ~ "</" ~ tag ~ '>');
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
61
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
62 return source.contains(pattern ~ '>') && source.contains("</" ~ tag ~ '>');
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
63 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
64
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
65 enum Foo { a, b, c }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
66 typedef int Int;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
67
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
68 class A
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
69 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
70 equals_t opEquals (Object other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
71 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
72 if (auto o = cast(A) other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
73 return true;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
74
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
75 return false;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
76 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
77 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
78
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
79 struct B
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
80 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
81 equals_t opEquals (B b)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
82 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
83 return true;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
84 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
85 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
86
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
87 class C { string str; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
88 class D { int[] arr; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
89 class E { int[int] aa; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
90 class F { int value; int* ptr; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
91 class G { Foo foo; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
92
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
93 class H
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
94 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
95 bool bool_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
96 byte byte_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
97 //cdouble cdouble_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
98 //cent cent_; // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
99 //cfloat cfloat_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
100 char char_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
101 //creal creal_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
102 dchar dchar_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
103 double double_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
104 float float_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
105 //idouble idouble_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
106 //ifloat ifloat_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
107 int int_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
108 //ireal ireal_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
109 long long_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
110 real real_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
111 short short_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
112 ubyte ubyte_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
113 //ucent ucent_; // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
114 uint uint_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
115 ulong ulong_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
116 ushort ushort_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
117 wchar wchar_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
118
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
119 equals_t opEquals (Object other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
120 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
121 if (auto o = cast(H) other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
122 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
123 return bool_ == o.bool_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
124 byte_ == o.byte_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
125 //cdouble_ == o.cdouble_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
126 //cent_ == o.cent_ && // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
127 //cfloat_ == o.cfloat_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
128 char_ == o.char_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
129 //creal_ == o.creal_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
130 dchar_ == o.dchar_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
131 double_ == o.double_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
132 float_ == o.float_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
133 //idouble_ == o.idouble_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
134 //ifloat_ == o.ifloat_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
135 int_ == o.int_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
136 //ireal_ == o.ireal_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
137 long_ == o.long_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
138 real_ == o.real_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
139 short_ == o.short_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
140 ubyte_ == o.ubyte_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
141 //ucent_ == o.ucent_ && // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
142 uint_ == o.uint_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
143 ulong_ == o.ulong_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
144 ushort_ == o.ushort_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
145 wchar_ == o.wchar_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
146 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
147
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
148 return false;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
149 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
150 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
151
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
152 class I
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
153 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
154 Int a;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
155 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
156
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
157 class J
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
158 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
159 string firstSource;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
160 string firstSlice;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
161
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
162 string secondSlice;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
163 string secondSource;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
164 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
165
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
166 class K
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
167 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
168 int[int] a;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
169 int[int] b;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
170 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
171
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
172 import orange.test.UnitTester;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
173 Serializer serializer;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
174 XMLArchive!(char) archive;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
175
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
176 A a;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
177 B b;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
178 C c;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
179 D d;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
180 E e;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
181 F f;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
182 G g;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
183 H h;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
184 I i;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
185 J j;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
186 J jDeserialized;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
187 K k;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
188
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
189 string data;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
190
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
191 unittest
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
192 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
193 archive = new XMLArchive!(char);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
194 serializer = new Serializer(archive);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
195
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
196 a = new A;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
197
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
198 c = new C;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
199 c.str = "foo";
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
200
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
201 d = new D;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
202 d.arr = [27, 382, 283, 3820, 32, 832].dup;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
203
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
204 e = new E;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
205 e.aa = [3 : 4, 1 : 2, 39 : 472, 6 : 7];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
206
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
207 f = new F;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
208 f.value = 9;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
209 f.ptr = &f.value;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
210
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
211 g = new G;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
212 g.foo = Foo.b;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
213
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
214 h = new H;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
215 h.bool_ = true;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
216 h.byte_ = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
217 h.char_ = 'a';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
218 //h.cdouble_ = 0.0 + 0.0 * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
219 //h.cfloat_ = 0.0f + 0.0f * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
220 //h.creal_ = 0.0 + 0.0 * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
221 h.dchar_ = 'b';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
222 h.double_ = 0.0;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
223 h.float_ = 0.0f;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
224 //h.idouble_ = 0.0 * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
225 //h.ifloat_ = 0.0f * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
226 h.int_ = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
227 //h.ireal_ = 0.0 * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
228 h.long_ = 1L;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
229 h.real_ = 0.0;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
230 h.short_ = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
231 h.ubyte_ = 1U;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
232 h.uint_ = 1U;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
233 h.ulong_ = 1LU;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
234 h.ushort_ = 1U;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
235 h.wchar_ = 'c';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
236
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
237 i = new I;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
238 i.a = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
239
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
240 j = new J;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
241 j.firstSource = "0123456789";
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
242 j.firstSlice = j.firstSource[3 .. 7];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
243 j.secondSource = "abcdefg";
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
244 j.secondSlice = j.secondSource[1 .. 4];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
245
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
246 k = new K;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
247 k.a = [3 : 4, 1 : 2, 39 : 472, 6 : 7];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
248 k.b = k.a;
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
249
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
250 describe("Serializer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
251 describe("serialize object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
252 it("should return a serialized object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
253 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
254 serializer.serialize(a);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
255
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
256 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
257 assert(archive.data().contains(`<object runtimeType="tests.Serializer.A" type="A" key="0" id="0"/>`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
258 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
259 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
260
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
261 describe("deserialize object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
262 it("should return a deserialized object equal to the original object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
263 auto aDeserialized = serializer.deserialize!(A)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
264 assert(a == aDeserialized);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
265 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
266 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
267
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
268 describe("serialize struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
269 it("should return a serialized struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
270 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
271 serializer.serialize(B());
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
272
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
273 assert(archive.data().containsDefaultXmlContent());
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
274 assert(archive.data().contains(`<struct type="B" key="0" id="0"/>`));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
275 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
276 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
277
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
278 describe("deserialize struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
279 it("should return a deserialized struct equal to the original struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
280 auto bDeserialized = serializer.deserialize!(B)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
281 assert(b == bDeserialized);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
282 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
283 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
284
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
285 describe("serialize string") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
286 it("should return a serialized string") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
287 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
288
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
289 serializer.serialize(c);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
290 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
291 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.C" type="C" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
292 assert(archive.data().containsXmlTag("string", `type="char" length="3" key="str" id="1"`, "foo"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
293 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
294 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
295
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
296 describe("deserialize string") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
297 it("should return a deserialized string equal to the original string") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
298 auto cDeserialized = serializer.deserialize!(C)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
299 assert(c.str == cDeserialized.str);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
300 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
301 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
302
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
303 describe("serialize array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
304 it("should return a serialized array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
305 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
306 serializer.serialize(d);
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
307
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
308 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
309 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.D" type="D" key="0" id="0"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
310 assert(archive.data().containsXmlTag("array", `type="int" length="6" key="arr" id="1"`));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
311 assert(archive.data().containsXmlTag("int", `key="0" id="2"`, "27"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
312 assert(archive.data().containsXmlTag("int", `key="1" id="3"`, "382"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
313 assert(archive.data().containsXmlTag("int", `key="2" id="4"`, "283"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
314 assert(archive.data().containsXmlTag("int", `key="3" id="5"`, "3820"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
315 assert(archive.data().containsXmlTag("int", `key="4" id="6"`, "32"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
316 assert(archive.data().containsXmlTag("int", `key="5" id="7"`, "832"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
317 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
318 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
319
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
320 describe("deserialize array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
321 it("should return a deserialize array equal to the original array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
322 auto dDeserialized = serializer.deserialize!(D)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
323 assert(d.arr == dDeserialized.arr);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
324 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
325 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
326
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
327 describe("serialize associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
328 it("should return a serialized associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
329 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
330 serializer.serialize(e);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
331
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
332 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
333 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.E" type="E" key="0" id="0"`));
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
334 assert(archive.data().containsXmlTag("associativeArray", `keyType="int" valueType="int" length="4" key="aa" id="1"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
335
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
336 assert(archive.data().containsXmlTag("key", `key="0"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
337 assert(archive.data().containsXmlTag("int", `key="0" id="2"`, "1"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
338 assert(archive.data().containsXmlTag("value", `key="0"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
339 assert(archive.data().containsXmlTag("int", `key="0" id="3"`, "2"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
340
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
341 assert(archive.data().containsXmlTag("key", `key="1"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
342 assert(archive.data().containsXmlTag("int", `key="1" id="4"`, "3"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
343 assert(archive.data().containsXmlTag("value", `key="1"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
344 assert(archive.data().containsXmlTag("int", `key="1" id="5"`, "4"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
345
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
346 assert(archive.data().containsXmlTag("key", `key="2"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
347 assert(archive.data().containsXmlTag("int", `key="2" id="6"`, "6"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
348 assert(archive.data().containsXmlTag("value", `key="2"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
349 assert(archive.data().containsXmlTag("int", `key="2" id="7"`, "7"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
350
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
351 assert(archive.data().containsXmlTag("key", `key="3"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
352 assert(archive.data().containsXmlTag("int", `key="3" id="8"`, "39"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
353 assert(archive.data().containsXmlTag("value", `key="3"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
354 assert(archive.data().containsXmlTag("int", `key="3" id="9"`, "472"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
355 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
356 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
357
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
358 describe("deserialize associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
359 it("should return an associative array equal to the original associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
360 auto eDeserialized = serializer.deserialize!(E)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
361
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
362 foreach (k, v ; eDeserialized.aa)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
363 assert(e.aa[k] == v);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
364
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
365 //assert(e.aa == eDeserialized.aa); // cannot compare associative array
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
366 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
367 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
368
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
369 describe("serialize pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
370 it("should return a serialized pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
371 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
372 serializer.serialize(f);
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
373
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
374 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
375 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.F" type="F" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
376 assert(archive.data().containsXmlTag("pointer", `key="ptr" id="2"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
377 assert(archive.data().containsXmlTag("reference", null, "1"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
378 assert(archive.data().containsXmlTag("int", `key="value" id="1"`, "9"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
379 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
380 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
381
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
382 describe("deserialize pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
383 it("should return a deserialized pointer equal to the original pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
384 auto fDeserialized = serializer.deserialize!(F)(archive.data);
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
385
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
386 assert(*f.ptr == *fDeserialized.ptr);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
387 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
388 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
389
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
390 describe("serialize enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
391 it("should return a serialized enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
392 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
393 serializer.serialize(g);
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
394
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
395 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
396 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.G" type="G" key="0" id="0"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
397 assert(archive.data().containsXmlTag("enum", `type="Foo" baseType="int" key="foo" id="1"`, "1"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
398 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
399 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
400
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
401
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
402 describe("deserialize enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
403 it("should return an enum equal to the original enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
404 auto gDeserialized = serializer.deserialize!(G)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
405 assert(g.foo == gDeserialized.foo);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
406 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
407 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
408
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
409 describe("serialize primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
410 it("should return serialized primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
411 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
412 serializer.serialize(h);
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
413
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
414 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
415 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.H" type="H" key="0" id="0"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
416 assert(archive.data().containsXmlTag("bool", `key="bool_" id="1"`, "true"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
417 assert(archive.data().containsXmlTag("byte", `key="byte_" id="2"`, "1"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
418 assert(archive.data().containsXmlTag("char", `key="char_" id="3"`, "a"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
419 assert(archive.data().containsXmlTag("dchar", `key="dchar_" id="4"`, "b"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
420 assert(archive.data().containsXmlTag("double", `key="double_" id="5"`, "0"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
421 assert(archive.data().containsXmlTag("float", `key="float_" id="6"`, "0"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
422 assert(archive.data().containsXmlTag("int", `key="int_" id="7"`, "1"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
423 assert(archive.data().containsXmlTag("long", `key="long_" id="8"`, "1"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
424 assert(archive.data().containsXmlTag("real", `key="real_" id="9"`, "0"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
425 assert(archive.data().containsXmlTag("short", `key="short_" id="10"`, "1"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
426 assert(archive.data().containsXmlTag("ubyte", `key="ubyte_" id="11"`, "1"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
427 assert(archive.data().containsXmlTag("uint", `key="uint_" id="12"`, "1"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
428 assert(archive.data().containsXmlTag("ulong", `key="ulong_" id="13"`, "1"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
429 assert(archive.data().containsXmlTag("ushort", `key="ushort_" id="14"`, "1"));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
430 assert(archive.data().containsXmlTag("wchar", `key="wchar_" id="15"`, "c"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
431 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
432 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
433
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
434 describe("deserialize primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
435 it("should return deserialized primitives equal to the original primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
436 auto hDeserialized = serializer.deserialize!(H)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
437 assert(h == hDeserialized);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
438 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
439 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
440
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
441 describe("serialize typedef") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
442 it("should return a serialized typedef") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
443 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
444 serializer.serialize(i);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
445 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
446 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.I" type="I" key="0" id="0"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
447 assert(archive.data().containsXmlTag("typedef", `type="Int" key="a" id="2"`));
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
448 assert(archive.data().containsXmlTag("int", `key="1" id="3"`, "1"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
449 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
450 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
451
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
452 describe("deserialize typedef") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
453 it("should return a deserialized typedef equal to the original typedef") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
454 auto iDeserialized = serializer.deserialize!(I)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
455 assert(i.a == iDeserialized.a);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
456 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
457 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
458
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
459 describe("serialize slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
460 it("should return serialized slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
461 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
462 serializer.serialize(j);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
463
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
464 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
465 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.J" type="J" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
466 assert(archive.data().containsXmlTag("string", `type="char" length="10" key="firstSource" id="1"`, "0123456789"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
467 assert(archive.data().containsXmlTag("slice", `key="firstSlice" offset="3" length="4"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
468 assert(archive.data().containsXmlTag("slice", `key="secondSlice" offset="1" length="3"`, "4"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
469 assert(archive.data().containsXmlTag("string", `type="char" length="7" key="secondSource" id="4"`, "abcdefg"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
470 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
471 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
472
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
473 describe("deserialize slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
474 jDeserialized = serializer.deserialize!(J)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
475
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
476 it("should return deserialized strings equal to the original strings") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
477 assert(j.firstSource == jDeserialized.firstSource);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
478 assert(j.secondSource == jDeserialized.secondSource);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
479 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
480
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
481 it("should return deserialized slices equal to the original slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
482 assert(j.firstSlice == jDeserialized.firstSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
483 assert(j.secondSlice == jDeserialized.secondSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
484 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
485
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
486 it("the slices should be equal to a slice of the original sources") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
487 assert(jDeserialized.firstSource[3 .. 7] == jDeserialized.firstSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
488 assert(jDeserialized.secondSource[1 .. 4] == jDeserialized.secondSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
489
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
490 assert(j.firstSource[3 .. 7] == jDeserialized.firstSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
491 assert(j.secondSource[1 .. 4] == jDeserialized.secondSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
492 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
493
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
494 it("the slices should be able to modify the sources") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
495 jDeserialized.firstSlice[0] = 'a';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
496 jDeserialized.secondSlice[0] = '0';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
497
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
498 assert(jDeserialized.firstSource == "012a456789");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
499 assert(jDeserialized.secondSource == "a0cdefg");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
500 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
501 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
502
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
503 describe("serialize associative array references") in {
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
504 it("should return a serialized associative array and a serialized reference") in {
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
505 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
506 serializer.serialize(k);
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
507
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
508 assert(archive.data().containsDefaultXmlContent());
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
509 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.K" type="K" key="0" id="0"`));
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
510 assert(archive.data().containsXmlTag("associativeArray", `keyType="int" valueType="int" length="4" key="a" id="1"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
511
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
512 assert(archive.data().containsXmlTag("key", `key="0"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
513 assert(archive.data().containsXmlTag("int", `key="0" id="2"`, "1"));
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
514 assert(archive.data().containsXmlTag("value", `key="0"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
515 assert(archive.data().containsXmlTag("int", `key="0" id="3"`, "2"));
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
516
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
517 assert(archive.data().containsXmlTag("key", `key="1"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
518 assert(archive.data().containsXmlTag("int", `key="1" id="4"`, "3"));
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
519 assert(archive.data().containsXmlTag("value", `key="1"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
520 assert(archive.data().containsXmlTag("int", `key="1" id="5"`, "4"));
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
521
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
522 assert(archive.data().containsXmlTag("key", `key="2"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
523 assert(archive.data().containsXmlTag("int", `key="2" id="6"`, "6"));
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
524 assert(archive.data().containsXmlTag("value", `key="2"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
525 assert(archive.data().containsXmlTag("int", `key="2" id="7"`, "7"));
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
526
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
527 assert(archive.data().containsXmlTag("key", `key="3"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
528 assert(archive.data().containsXmlTag("int", `key="3" id="8"`, "39"));
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
529 assert(archive.data().containsXmlTag("value", `key="3"`));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
530 assert(archive.data().containsXmlTag("int", `key="3" id="9"`, "472"));
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
531
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
532 assert(archive.data().containsXmlTag("reference", `key="b"`, "1"));
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
533 };
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
534 };
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
535
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
536 describe("deserialize associative array references") in {
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
537 it("should return two deserialized associative arrays pointing to the same data") in {
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
538 auto kDeserialized = serializer.deserialize!(K)(archive.data);
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
539
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
540 assert(kDeserialized.a is kDeserialized.b);
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
541 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
542 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
543 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
544 }