annotate tests/Serializer.d @ 36:c523d436052f experimental

Fixed an D1 error in the unit test.
author Jacob Carlborg <doob@me.com>
date Wed, 03 Aug 2011 21:45:56 +0200
parents 511d1ef4e299
children 9443bcddc699
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 {
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
36 return source.contains(`<archive type="org.dsource.orange.xml" version="1.0.0">`) ||
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
37 source.contains(`<archive version="1.0.0" type="org.dsource.orange.xml">`);
27
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
40 bool containsXmlTag (string source, string tag, bool simple = false)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
41 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 return source.containsXmlTag(tag, null, null, simple);
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45 bool containsXmlTag (string source, string tag, string attributes, bool simple = false)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
47 return source.containsXmlTag(tag, attributes, null, simple);
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50 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
51 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
52 string pattern = '<' ~ tag;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
53
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54 if (attributes.length > 0)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55 pattern ~= ' ' ~ attributes;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 if (simple)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58 return source.contains(pattern ~ "/>");
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
59
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
60 if (content.length > 0)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
61 return source.contains(pattern ~ '>' ~ content ~ "</" ~ tag ~ '>');
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
62
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
63 return source.contains(pattern ~ '>') && source.contains("</" ~ tag ~ '>');
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
66 enum Foo { a, b, c }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
67 typedef int Int;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
68
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
69 class A
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
70 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
71 equals_t opEquals (Object other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
72 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
73 if (auto o = cast(A) other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
74 return true;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
75
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
76 return false;
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
80 struct B
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
81 {
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
82 version (Tango)
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
83 {
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
84 equals_t opEquals (B b)
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
85 {
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
86 return true;
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
87 }
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
88 }
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
89
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
90 else
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
91 {
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
92 mixin(`bool opEquals (ref const B) const
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
93 {
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
94 return true;
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
95 }`);
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
96 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
97 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
98
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
99 class C { string str; wstring wstr; dstring dstr; }
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
100 class D { int[] arr; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
101 class E { int[int] aa; }
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
102 class F { int value; int* ptr; int* ptr2; }
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
103 class G { Foo foo; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
104
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
105 int pointee;
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
106
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
107 class H
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
108 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
109 bool bool_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
110 byte byte_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
111 //cdouble cdouble_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
112 //cent cent_; // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
113 //cfloat cfloat_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
114 char char_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
115 //creal creal_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
116 dchar dchar_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
117 double double_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
118 float float_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
119 //idouble idouble_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
120 //ifloat ifloat_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
121 int int_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
122 //ireal ireal_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
123 long long_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
124 real real_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
125 short short_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
126 ubyte ubyte_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
127 //ucent ucent_; // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
128 uint uint_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
129 ulong ulong_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
130 ushort ushort_;
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
131
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
132 version (Tango)
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
133 wchar wchar_; // Phobos to!() function can't handle string -> wchar
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
134
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
135 equals_t opEquals (Object other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
136 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
137 if (auto o = cast(H) other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
138 {
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
139 auto result = bool_ == o.bool_ &&
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
140 byte_ == o.byte_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
141 //cdouble_ == o.cdouble_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
142 //cent_ == o.cent_ && // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
143 //cfloat_ == o.cfloat_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
144 char_ == o.char_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
145 //creal_ == o.creal_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
146 dchar_ == o.dchar_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
147 double_ == o.double_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
148 float_ == o.float_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
149 //idouble_ == o.idouble_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
150 //ifloat_ == o.ifloat_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
151 int_ == o.int_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
152 //ireal_ == o.ireal_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
153 long_ == o.long_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
154 real_ == o.real_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
155 short_ == o.short_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
156 ubyte_ == o.ubyte_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
157 //ucent_ == o.ucent_ && // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
158 uint_ == o.uint_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
159 ulong_ == o.ulong_ &&
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
160 ushort_ == o.ushort_;
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
161
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
162 version (Tango)
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
163 return result && wchar_ == o.wchar_;
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
164
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
165 else
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
166 return result;
27
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
169 return false;
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
173 class I
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
174 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
175 Int a;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
176 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
177
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
178 class J
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
179 {
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
180 int[] firstSource;
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
181 int[] firstSlice;
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
182
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
183 int[] secondSlice;
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
184 int[] secondSource;
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
185 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
186
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
187 class 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 int[int] a;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
190 int[int] b;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
191 }
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 import orange.test.UnitTester;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
194 Serializer serializer;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
195 XMLArchive!(char) archive;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
196
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
197 A a;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
198 B b;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
199 C c;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
200 D d;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
201 E e;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
202 F f;
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
203 F fDeserialized;
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
204 G g;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
205 H h;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
206 I i;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
207 J j;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
208 J jDeserialized;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
209 K k;
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 string data;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
212
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
213 unittest
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
214 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
215 archive = new XMLArchive!(char);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
216 serializer = new Serializer(archive);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
217
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
218 a = new A;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
219
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
220 c = new C;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
221 c.str = "foo";
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
222 c.wstr = "bar";
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
223 c.dstr = "foobar";
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
224
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
225
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
226 d = new D;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
227 d.arr = [27, 382, 283, 3820, 32, 832].dup;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
228
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
229 e = new E;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
230 e.aa = [3 : 4, 1 : 2, 39 : 472, 6 : 7];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
231
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
232 pointee = 3;
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
233 f = new F;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
234 f.value = 9;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
235 f.ptr = &f.value;
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
236 f.ptr2 = &pointee;
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
237
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
238 g = new G;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
239 g.foo = Foo.b;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
240
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
241 h = new H;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
242 h.bool_ = true;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
243 h.byte_ = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
244 h.char_ = 'a';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
245 //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
246 //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
247 //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
248 h.dchar_ = 'b';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
249 h.double_ = 0.0;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
250 h.float_ = 0.0f;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
251 //h.idouble_ = 0.0 * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
252 //h.ifloat_ = 0.0f * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
253 h.int_ = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
254 //h.ireal_ = 0.0 * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
255 h.long_ = 1L;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
256 h.real_ = 0.0;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
257 h.short_ = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
258 h.ubyte_ = 1U;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
259 h.uint_ = 1U;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
260 h.ulong_ = 1LU;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
261 h.ushort_ = 1U;
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
262
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
263 version (Tango)
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
264 h.wchar_ = 'c';
27
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 i = new I;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
267 i.a = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
268
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
269 j = new J;
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
270 j.firstSource = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].dup;
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
271 j.firstSlice = j.firstSource[3 .. 7];
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
272 j.secondSource = [10, 11, 12, 13, 14, 15].dup;
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
273 j.secondSlice = j.secondSource[1 .. 4];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
274
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
275 k = new K;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
276 k.a = [3 : 4, 1 : 2, 39 : 472, 6 : 7];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
277 k.b = k.a;
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
278
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
279 describe("Serializer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
280 describe("serialize object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
281 it("should return a serialized object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
282 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
283 serializer.serialize(a);
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
284
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
285 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
286 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
287 };
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
290 describe("deserialize object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
291 it("should return a deserialized object equal to the original object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
292 auto aDeserialized = serializer.deserialize!(A)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
293 assert(a == aDeserialized);
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
297 describe("serialize struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
298 it("should return a serialized struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
299 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
300 serializer.serialize(B());
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
301
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
302 assert(archive.data().containsDefaultXmlContent());
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
303 assert(archive.data().contains(`<struct type="B" key="0" id="0"/>`));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
304 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
305 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
306
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
307 describe("deserialize struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
308 it("should return a deserialized struct equal to the original struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
309 auto bDeserialized = serializer.deserialize!(B)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
310 assert(b == bDeserialized);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
311 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
312 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
313
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
314 describe("serialize strings") in {
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
315 it("should return serialized strings") in {
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
316 serializer.reset;
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
317 serializer.serialize(c);
27
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 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
320 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.C" type="C" key="0" id="0"`));
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
321
36
c523d436052f Fixed an D1 error in the unit test.
Jacob Carlborg <doob@me.com>
parents: 35
diff changeset
322 version (Tango) string type = "char";
c523d436052f Fixed an D1 error in the unit test.
Jacob Carlborg <doob@me.com>
parents: 35
diff changeset
323 else string type = "immutable(char)";
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
324
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
325 assert(archive.data().containsXmlTag("string", `type="` ~ type ~ `" length="3" key="str" id="1"`, "foo"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
326
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
327 version (Tango) type = "wchar";
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
328 else type = "immutable(wchar)";
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
329
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
330 assert(archive.data().containsXmlTag("string", `type="` ~ type ~ `" length="3" key="wstr" id="2"`, "bar"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
331
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
332 version (Tango) type = "dchar";
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
333 else type = "immutable(dchar)";
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
334
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
335 assert(archive.data().containsXmlTag("string", `type="` ~ type ~ `" length="6" key="dstr" id="3"`, "foobar"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
336 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
337 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
338
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
339 describe("deserialize string") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
340 it("should return a deserialized string equal to the original string") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
341 auto cDeserialized = serializer.deserialize!(C)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
342 assert(c.str == cDeserialized.str);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
343 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
344 };
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 describe("serialize array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
347 it("should return a serialized array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
348 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
349 serializer.serialize(d);
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
350
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
351 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
352 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
353 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
354 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
355 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
356 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
357 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
358 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
359 assert(archive.data().containsXmlTag("int", `key="5" id="7"`, "832"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
360 };
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
363 describe("deserialize array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
364 it("should return a deserialize array equal to the original array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
365 auto dDeserialized = serializer.deserialize!(D)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
366 assert(d.arr == dDeserialized.arr);
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
370 describe("serialize associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
371 it("should return a serialized associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
372 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
373 serializer.serialize(e);
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
374
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
375 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
376 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.E" type="E" key="0" id="0"`));
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
377 version (Tango) 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
378
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
379 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
380 assert(archive.data().containsXmlTag("int", `key="0" id="2"`, "1"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
381 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
382 assert(archive.data().containsXmlTag("int", `key="0" id="3"`, "2"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
383
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
384 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
385 assert(archive.data().containsXmlTag("int", `key="1" id="4"`, "3"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
386 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
387 assert(archive.data().containsXmlTag("int", `key="1" id="5"`, "4"));
27
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 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
390 assert(archive.data().containsXmlTag("int", `key="2" id="6"`, "6"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
391 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
392 assert(archive.data().containsXmlTag("int", `key="2" id="7"`, "7"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
393
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
394 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
395 assert(archive.data().containsXmlTag("int", `key="3" id="8"`, "39"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
396 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
397 assert(archive.data().containsXmlTag("int", `key="3" id="9"`, "472"));
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 describe("deserialize associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
402 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
403 auto eDeserialized = serializer.deserialize!(E)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
404
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
405 foreach (k, v ; eDeserialized.aa)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
406 assert(e.aa[k] == v);
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 //assert(e.aa == eDeserialized.aa); // cannot compare associative array
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
409 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
410 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
411
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
412 describe("serialize pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
413 it("should return a serialized pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
414 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
415 serializer.serialize(f);
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
416
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
417 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
418 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
419 assert(archive.data().containsXmlTag("pointer", `key="ptr" id="2"`));
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
420 assert(archive.data().containsXmlTag("reference", `key="1"`, "1"));
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
421 assert(archive.data().containsXmlTag("int", `key="value" id="1"`, "9"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
422 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
423 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
424
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
425 describe("deserialize pointer") in {
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
426 fDeserialized = serializer.deserialize!(F)(archive.data);
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
427
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
428 it("should return a deserialized pointer equal to the original pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
429 assert(*f.ptr == *fDeserialized.ptr);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
430 };
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
431
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
432 it("the pointer should point to the deserialized value") in {
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
433 assert(fDeserialized.ptr == &fDeserialized.value);
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
434 };
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
435 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
436
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
437 describe("serialize enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
438 it("should return a serialized enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
439 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
440 serializer.serialize(g);
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
441
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
442 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
443 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
444 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
445 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
446 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
447
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
448
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
449 describe("deserialize enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
450 it("should return an enum equal to the original enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
451 auto gDeserialized = serializer.deserialize!(G)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
452 assert(g.foo == gDeserialized.foo);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
453 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
454 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
455
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
456 describe("serialize primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
457 it("should return serialized primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
458 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
459 serializer.serialize(h);
32
9df3b7a46a51 Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents: 28
diff changeset
460
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
461 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
462 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
463 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
464 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
465 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
466 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
467 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
468 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
469 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
470 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
471 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
472 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
473 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
474 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
475 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
476 assert(archive.data().containsXmlTag("ushort", `key="ushort_" id="14"`, "1"));
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
477
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
478 version (Tango)
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
479 assert(archive.data().containsXmlTag("wchar", `key="wchar_" id="15"`, "c"));
27
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 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
482
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
483 describe("deserialize primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
484 it("should return deserialized primitives equal to the original primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
485 auto hDeserialized = serializer.deserialize!(H)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
486 assert(h == hDeserialized);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
487 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
488 };
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 describe("serialize typedef") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
491 it("should return a serialized typedef") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
492 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
493 serializer.serialize(i);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
494 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
495 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
496 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
497 assert(archive.data().containsXmlTag("int", `key="1" id="3"`, "1"));
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
498 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
499 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
500
33
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
501 // describe("deserialize typedef") in {
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
502 // it("should return a deserialized typedef equal to the original typedef") in {
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
503 // auto iDeserialized = serializer.deserialize!(I)(archive.data);
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
504 // assert(i.a == iDeserialized.a);
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
505 // };
4fea56a5849f Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents: 32
diff changeset
506 // };
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
507
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
508 describe("serialize slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
509 it("should return serialized slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
510 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
511 serializer.serialize(j);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
512
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
513 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
514 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.J" type="J" key="0" id="0"`));
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
515 assert(archive.data().containsXmlTag("array", `type="int" length="10" key="firstSource" id="1"`));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
516
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
517 assert(archive.data().containsXmlTag("int", `key="0" id="2"`, "0"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
518 assert(archive.data().containsXmlTag("int", `key="1" id="3"`, "1"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
519 assert(archive.data().containsXmlTag("int", `key="2" id="4"`, "2"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
520 assert(archive.data().containsXmlTag("int", `key="3" id="5"`, "3"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
521 assert(archive.data().containsXmlTag("int", `key="4" id="6"`, "4"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
522 assert(archive.data().containsXmlTag("int", `key="5" id="7"`, "5"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
523 assert(archive.data().containsXmlTag("int", `key="6" id="8"`, "6"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
524 assert(archive.data().containsXmlTag("int", `key="7" id="9"`, "7"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
525 assert(archive.data().containsXmlTag("int", `key="8" id="10"`, "8"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
526 assert(archive.data().containsXmlTag("int", `key="9" id="11"`, "9"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
527
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
528 version (Tango)
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
529 {
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
530 assert(archive.data().containsXmlTag("slice", `key="firstSlice" offset="3" length="4"`, "1"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
531 assert(archive.data().containsXmlTag("slice", `key="secondSlice" offset="1" length="3"`, "21"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
532 }
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
533
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
534 assert(archive.data().containsXmlTag("array", `type="int" length="6" key="secondSource" id="21"`));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
535
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
536 assert(archive.data().containsXmlTag("int", `key="0" id="22"`, "10"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
537 assert(archive.data().containsXmlTag("int", `key="1" id="23"`, "11"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
538 assert(archive.data().containsXmlTag("int", `key="2" id="24"`, "12"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
539 assert(archive.data().containsXmlTag("int", `key="3" id="25"`, "13"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
540 assert(archive.data().containsXmlTag("int", `key="4" id="26"`, "14"));
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
541 assert(archive.data().containsXmlTag("int", `key="5" id="27"`, "15"));
27
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
545 describe("deserialize slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
546 jDeserialized = serializer.deserialize!(J)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
547
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
548 it("should return deserialized strings equal to the original strings") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
549 assert(j.firstSource == jDeserialized.firstSource);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
550 assert(j.secondSource == jDeserialized.secondSource);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
551 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
552
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
553 it("should return deserialized slices equal to the original slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
554 assert(j.firstSlice == jDeserialized.firstSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
555 assert(j.secondSlice == jDeserialized.secondSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
556 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
557
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
558 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
559 assert(jDeserialized.firstSource[3 .. 7] == jDeserialized.firstSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
560 assert(jDeserialized.secondSource[1 .. 4] == jDeserialized.secondSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
561
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
562 assert(j.firstSource[3 .. 7] == jDeserialized.firstSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
563 assert(j.secondSource[1 .. 4] == jDeserialized.secondSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
564 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
565
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
566 it("the slices should be able to modify the sources") in {
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
567 jDeserialized.firstSlice[0] = 55;
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
568 jDeserialized.secondSlice[0] = 3;
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
569
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
570 assert(jDeserialized.firstSource == [0, 1, 2, 55, 4, 5, 6, 7, 8, 9]);
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
571 assert(jDeserialized.secondSource == [10, 3, 12, 13, 14, 15]);
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
572 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
573 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
574
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
575 describe("serialize associative array references") in {
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
576 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
577 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
578 serializer.serialize(k);
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
579
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
580 assert(archive.data().containsDefaultXmlContent());
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
581 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.K" type="K" key="0" id="0"`));
35
511d1ef4e299 Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents: 33
diff changeset
582 version (Tango) 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
583
28
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
584 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
585 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
586 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
587 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
588
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
589 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
590 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
591 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
592 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
593
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
594 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
595 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
596 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
597 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
598
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
599 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
600 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
601 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
602 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
603
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
604 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
605 };
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
606 };
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
607
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
608 describe("deserialize associative array references") in {
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
609 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
610 auto kDeserialized = serializer.deserialize!(K)(archive.data);
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
611
bffcbc8c392b Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 27
diff changeset
612 assert(kDeserialized.a is kDeserialized.b);
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
613 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
614 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
615 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
616 }