1 module it.c.run.struct_;
2 
3 import it;
4 
5 @Tags("run")
6 @("structs")
7 @safe unittest {
8     shouldRun(
9         C(
10             q{
11                 struct Foo { int i; };
12 
13                 struct Bar { double d; };
14 
15                 struct Outer {
16                     struct Inner {
17                         int x;
18                     } inner;
19                 };
20 
21                 typedef struct TypeDefd_ {
22                     int i;
23                     double d;
24                    } TypeDefd;
25 
26                 typedef struct {
27                     int x, y;
28                 } Nameless1;
29 
30                 typedef struct {
31                     double d;
32                 } Nameless2;
33             }
34         ),
35         C(q{}),
36         D(
37             q{
38                 auto f = Foo(5);
39                 assert(f.sizeof == 4, "Wrong sizeof for Foo");
40                 assert(f.i == 5, "f.i should be 5");
41 
42                 auto b = Bar(33.3);
43                 assert(b.sizeof == 8, "Wrong sizeof for Foo");
44                 assert(b.d == 33.3, "b.d should be 33.3");
45 
46                 auto o = Outer(Outer.Inner(42));
47                 assert(o.sizeof == 4, "Wrong sizeof for Outer");
48                 assert(o.inner.x == 42, "o.innter.x should be 42");
49 
50                 {
51                     auto t = TypeDefd_(42, 33.3);
52                     assert(t.sizeof == 16, "Wrong sizeof for TypeDefd_");
53                     assert(t.i == 42, "t.i should be 42");
54                     assert(t.d == 33.3, "t.d should be 33.3");
55                 }
56                 {
57                     auto t = TypeDefd(42, 33.3);
58                     assert(t.sizeof == 16, "Wrong sizeof for TypeDefd");
59                     assert(t.i == 42, "t.i should be 42");
60                     assert(t.d == 33.3, "t.d should be 33.3");
61                 }
62 
63                 auto n1 = Nameless1(2, 3);
64                 assert(n1.sizeof == 8, "Wrong sizeof for Nameless1");
65                 assert(n1.x == 2, "n1.x should be 2");
66                 assert(n1.y == 3, "n1.y should be 3");
67 
68                 auto n2 = Nameless2(33.3);
69                 assert(n2.sizeof == 8, "Wrong sizeof for Nameless2");
70                 assert(n2.d == 33.3, "n2.d should be 33.3");
71             }
72         ),
73     );
74 }