Mercurial > projects > orange
annotate tests/String.d @ 40:02dbd18b7fe9
Moved all tests into its own modules.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 06 Aug 2011 13:27:21 +0200 |
parents | |
children |
rev | line source |
---|---|
40
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
1 /** |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
2 * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved. |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
3 * Authors: Jacob Carlborg |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
4 * Version: Initial created: Aug 6, 2011 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
6 */ |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
7 module tests.String; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
8 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
9 import orange.core.string; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
10 import orange.serialization.Serializer; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
11 import orange.serialization.archives.XMLArchive; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
12 import orange.test.UnitTester; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
13 import tests.Util; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
14 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
15 Serializer serializer; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
16 XMLArchive!(char) archive; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
17 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
18 class C |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
19 { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
20 string str; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
21 wstring wstr; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
22 dstring dstr; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
23 } |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
24 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
25 C c; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
26 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
27 unittest |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
28 { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
29 archive = new XMLArchive!(char); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
30 serializer = new Serializer(archive); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
31 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
32 c = new C; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
33 c.str = "foo"; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
34 c.wstr = "bar"; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
35 c.dstr = "foobar"; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
36 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
37 describe("serialize strings") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
38 it("should return serialized strings") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
39 serializer.reset; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
40 serializer.serialize(c); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
41 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
42 assert(archive.data().containsDefaultXmlContent()); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
43 assert(archive.data().containsXmlTag("object", `runtimeType="tests.String.C" type="C" key="0" id="0"`)); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
44 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
45 version (Tango) string type = "char"; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
46 else string type = "immutable(char)"; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
47 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
48 assert(archive.data().containsXmlTag("string", `type="` ~ type ~ `" length="3" key="str" id="1"`, "foo")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
49 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
50 version (Tango) type = "wchar"; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
51 else type = "immutable(wchar)"; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
52 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
53 assert(archive.data().containsXmlTag("string", `type="` ~ type ~ `" length="3" key="wstr" id="2"`, "bar")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
54 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
55 version (Tango) type = "dchar"; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
56 else type = "immutable(dchar)"; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
57 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
58 assert(archive.data().containsXmlTag("string", `type="` ~ type ~ `" length="6" key="dstr" id="3"`, "foobar")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
59 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
60 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
61 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
62 describe("deserialize string") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
63 it("should return a deserialized string equal to the original string") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
64 auto cDeserialized = serializer.deserialize!(C)(archive.untypedData); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
65 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
66 assert(c.str == cDeserialized.str); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
67 assert(c.wstr == cDeserialized.wstr); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
68 assert(c.dstr == cDeserialized.dstr); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
69 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
70 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
71 } |