1 module ocean.meta.values.Reset_test;
2 
3 import ocean.meta.values.Reset;
4 import ocean.core.array.Mutation;
5 import ocean.core.Test;
6 
7 unittest
8 {
9     struct TestStruct
10     {
11         int a;
12         char[] b;
13         int[7] c;
14 
15         public struct SubStruct
16         {
17             int d;
18             char[] e;
19             char[][] f;
20             int[7] g;
21 
22             public struct SubSubStruct
23             {
24                 int h;
25                 char[] i;
26                 char[][] j;
27                 int[7] k;
28 
29                 void InitStructure()
30                 {
31                     this.h = -52;
32                     this.i.copy("even even more test text");
33                     this.j.length = 3;
34                     this.j[0].copy("abc");
35                     this.j[1].copy("def");
36                     this.j[2].copy("ghi");
37                     foreach ( ref item; this.k )
38                     {
39                         item = 120000;
40                     }
41                 }
42             }
43 
44             void InitStructure()
45             {
46                 this.d = 32;
47                 this.e.copy("even more test text");
48 
49                 this.f.length = 1;
50                 this.f[0].copy("abc");
51                 foreach ( ref item; this.g )
52                 {
53                     item = 32400;
54                 }
55             }
56 
57             SubSubStruct[] sub_sub_struct;
58             SubSubStruct[1] sub_sub_static_array;
59         }
60 
61         SubStruct sub_struct;
62 
63         SubStruct[] sub_struct_array;
64         int[][1] dynamic_static_array;
65     }
66 
67     TestStruct test_struct;
68     test_struct.a = 7;
69     test_struct.b.copy("some test");
70     foreach ( i, ref item; test_struct.c )
71     {
72         item = 64800;
73     }
74 
75     TestStruct.SubStruct sub_struct;
76     sub_struct.InitStructure;
77     test_struct.sub_struct = sub_struct;
78     test_struct.sub_struct_array ~= sub_struct;
79     test_struct.sub_struct_array ~= sub_struct;
80 
81 
82     TestStruct.SubStruct.SubSubStruct sub_sub_struct;
83     sub_sub_struct.InitStructure;
84     test_struct.sub_struct_array[0].sub_sub_struct ~= sub_sub_struct;
85     test_struct.sub_struct_array[1].sub_sub_struct ~= sub_sub_struct;
86     test_struct.sub_struct_array[1].sub_sub_struct ~= sub_sub_struct;
87     test_struct.sub_struct.sub_sub_struct ~= sub_sub_struct;
88     test_struct.sub_struct.sub_sub_struct ~= sub_sub_struct;
89     test_struct.sub_struct.sub_sub_static_array[0] = sub_sub_struct;
90 
91     test_struct.dynamic_static_array[0] = [ 1, 2, 3 ];
92 
93     reset(test_struct);
94 
95     test!("==")(test_struct.a, 0);
96     test!("==")(test_struct.b, ""[]);
97     foreach ( item; test_struct.c )
98     {
99         test!("==")(item, 0);
100     }
101 
102     test!("==")(test_struct.sub_struct_array.length, 0);
103 
104     test!("==")(test_struct.sub_struct.d, 0);
105     test!("==")(test_struct.sub_struct.e, ""[]);
106     test!("==")(test_struct.sub_struct.f.length, 0);
107     foreach ( item; test_struct.sub_struct.g )
108     {
109         test!("==")(item, 0);
110     }
111 
112     foreach (idx, ref field; test_struct.sub_struct.sub_sub_static_array[0].tupleof)
113     {
114         test!("==")(field, TestStruct.SubStruct.SubSubStruct.init.tupleof[idx]);
115     }
116 
117     test!("==")(test_struct.sub_struct.sub_sub_struct.length, 0);
118     test!("==")(test_struct.dynamic_static_array[0].length, 0);
119 
120     //Test nested classes.
121     class TestClass
122     {
123         int a;
124         char[] b;
125         int[2] c;
126 
127         public class SubClass
128         {
129             int d;
130             char[] e;
131         }
132 
133         SubClass[1] s;
134     }
135 
136     TestClass test_class = new TestClass;
137     test_class.s[0] =  test_class..new SubClass;
138     test_class.a = 7;
139     test_class.b = [];
140     test_class.b ~= 't';
141     test_class.c[1] = 1;
142     test_class.s[0].d = 5;
143     test_class.s[0].e = [];
144     test_class.s[0].e ~= 'q';
145 
146     reset(test_class);
147     test!("==")(test_class.a, 0);
148     test!("==")(test_class.b.length, 0);
149     test!("==")(test_class.c[1], 0);
150     test!("!is")(cast(void*)test_class.s, null);
151     test!("==")(test_class.s[0].d, 0);
152     test!("==")(test_class.s[0].e.length, 0);
153 }