1 /*******************************************************************************
2 
3     Copyright:
4         Copyright (c) 2018 dunnhumby Germany GmbH.
5         All rights reserved.
6 
7     License:
8         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
9         Alternatively, this file may be distributed under the terms of the Tango
10         3-Clause BSD License (see LICENSE_BSD.txt for details).
11 
12 *******************************************************************************/
13 
14 module ocean.meta.values.VisitValue_test;
15 
16 import ocean.meta.values.VisitValue;
17 import ocean.meta.traits.Basic;
18 import ocean.meta.types.Typedef;
19 import ocean.core.Test;
20 
21 struct SumIntegers
22 {
23     long sum;
24 
25     /// Returns: 'true' if recursion shall continue for this type
26     bool visit ( T ) ( T* value )
27     {
28         static if (isIntegerType!(T))
29         {
30             sum += *value;
31         }
32 
33         return true;
34     }
35 }
36 
37 mixin(Typedef!(int, "MyTypedef"));
38 
39 class A
40 {
41     int a;
42 }
43 
44 class B : A
45 {
46     int b;
47 }
48 
49 struct Test1
50 {
51     enum Num
52     {
53         One,
54         Two
55     }
56 
57     struct Nested
58     {
59         Num x;
60     }
61 
62     int[2][] arr;
63     byte field;
64     long* pfield;
65     Nested s;
66     MyTypedef td;
67     B obj;
68 }
69 
70 unittest
71 {
72     Test1 instance;
73     instance.arr = [ [ 1, 2 ], [ 3, 4 ] ];
74     instance.field = 5;
75     instance.pfield = new long;
76     *instance.pfield = 6;
77     instance.s.x = Test1.Num.One;
78     instance.td = 7;
79     instance.obj = new B;
80     instance.obj.a = 8;
81     instance.obj.b = 9;
82 
83     SumIntegers visitor;
84     visitValue(instance, visitor);
85     test!("==")(visitor.sum, 45);
86 }