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 spec.serialization.Enum;
8 
9 import dspec.Dsl;
10 
11 import mambo.core..string;
12 import mambo.serialization.Serializer;
13 import mambo.serialization.archives.XmlArchive;
14 import spec.serialization.Util;
15 
16 Serializer serializer;
17 XmlArchive!(char) archive;
18 
19 enum Foo
20 {
21 	a,
22 	b,
23 	c
24 }
25 
26 class G
27 {
28 	Foo foo;
29 }
30 
31 G g;
32 
33 unittest
34 {
35 	archive = new XmlArchive!(char);
36 	serializer = new Serializer(archive);
37 
38 	g = new G;
39 	g.foo = Foo.b;
40 
41 	describe! "serialize enum" in {
42 		it! "should return a serialized enum" in {
43 			serializer.reset();
44 			serializer.serialize(g);
45 	
46 			assert(archive.data().containsDefaultXmlContent());
47 			assert(archive.data().containsXmlTag("object", `runtimeType="spec.serialization.Enum.G" type="spec.serialization.Enum.G" key="0" id="0"`));
48 			assert(archive.data().containsXmlTag("enum", `type="spec.serialization.Enum.Foo" baseType="int" key="foo" id="1"`, "1"));
49 		};
50 	};
51 	
52 	
53 	describe! "deserialize enum" in {
54 		it! "should return an enum equal to the original enum" in {
55 			auto gDeserialized = serializer.deserialize!(G)(archive.untypedData);
56 			assert(g.foo == gDeserialized.foo);
57 		};
58 	};
59 }