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