1 
2 //          Copyright Luna & Cospec 2019.
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          https://www.boost.org/LICENSE_1_0.txt)
6 
7 module wsf.serialization;
8 public import wsf.serialization.serializer : serializeWSF;
9 public import wsf.serialization.deserializer : deserializeWSF;
10 public import wsf.ast.tag;
11 
12 /**
13     UDA
14 
15     Marks field to be ignored
16 */
17 enum ignore;
18 
19 /**
20     UDA
21 
22     Marks field as optional
23 */
24 enum optional;
25 
26 
27 //
28 // Unit-test territory
29 //
30 
31 private struct TestStruct {
32 private:
33     int privateTest = 128;
34 
35     struct iStruct {
36         ubyte b = 0;
37     }
38 
39 public:
40 
41     enum TestEnum {
42         A = 0,
43         B = 1
44     }
45 
46     @ignore
47     int ignoredTest = 42;
48 
49     @optional
50     string optionalTest = "optional value";
51 
52     @optional
53     iStruct internalStruct;
54 
55     int intValue = 0;
56 
57     string stringValue = "Test";
58 
59     int[] arrA = [0, 0, 0, 0];
60     int[][] matrix = [
61         [0, 0, 0, 0],
62         [0, 0, 0, 0],
63         [0, 0, 0, 0],
64         [0, 0, 0, 0]
65     ];
66 
67     string[string] aa;
68 
69     TestEnum enm;
70 
71 }
72 
73 unittest {
74     import std.stdio : writeln;
75     TestStruct* strct = new TestStruct;
76     strct.matrix[0][0] = 1;
77     strct.aa = [
78         "Test": "test",
79         "TestB": "test b"
80     ];
81     strct.enm = TestStruct.TestEnum.B;
82 
83     Tag serialized = serializeWSF(strct);
84     TestStruct deserialized = deserializeWSF!TestStruct(serialized);
85     assert(*strct == deserialized, "Outputs did not match!");
86 }