Debian Codegraph @

gcc/testsuite/gdc.test/runnable/test17684.d

raw
1 struct StructField(T)
2 {
3 static T Field;
4 static alias Field this;
5 }
6
7 struct StructProperty(T)
8 {
9 static T Field;
10
11 static @property T property()
12 {
13 return Field;
14 }
15
16 static @property void property(T value)
17 {
18 Field = value;
19 }
20
21 static alias property this;
22 }
23
24 class ClassField(T)
25 {
26 static T Field;
27 static alias Field this;
28 }
29
30 class ClassProperty(T)
31 {
32 static T Field;
33
34 static @property T property()
35 {
36 return Field;
37 }
38
39 static @property void property(T value)
40 {
41 Field = value;
42 }
43
44 static alias property this;
45 }
46
47 bool boolTest(T)()
48 {
49 alias t = T;
50
51 t = false; // tests AssignExp
52 assert(t == false);
53
54 bool boolValue = t; // tests AssignExp
55 assert(boolValue == false);
56
57 t = !t; // tests NotExp
58 assert(t == true);
59
60 boolValue = t;
61 assert(boolValue == true);
62
63 assert(boolValue && t); // tests AndAndExp
64 assert(t && boolValue);
65
66 boolValue = false;
67 assert(boolValue || t); // tests OrOrExp
68 assert(t || boolValue);
69
70 assert(t != boolValue); // tests CmpExp
71 assert(boolValue != t);
72
73 boolValue = true;
74 assert(t == boolValue);
75 assert(boolValue == t);
76
77 t = true; // tests inferType
78 auto inferredValue = t;
79 assert(inferredValue == true);
80
81 t = true; // tests function argument
82 bool functionCall(bool test)
83 {
84 return test;
85 }
86 assert(t == functionCall(t));
87
88 t = true; // tests CastExp
89 assert(t == cast(bool)t);
90
91 t = true;
92 return t; // tests ReturnStatement
93 }
94
95 int intTest(T)()
96 {
97 alias t = T;
98
99 t = 42; // tests AssignExp
100 assert(t == 42);
101
102 int intValue = t;
103 assert(intValue == 42);
104
105 assert(t == 42); // tests CmpExp
106 assert(42 == t);
107 assert(t != 43);
108 assert(43 != t);
109 assert(t < 43);
110 assert(43 > t);
111 assert(t <= 42);
112 assert(42 >= t);
113
114 t = 42; // tests CastExp
115 assert(42 == cast(int)t);
116
117 // These currently don't work for properties due to https://issues.dlang.org/show_bug.cgi?id=8006
118 static if (!(typeid(T) is typeid(StructProperty!int)) && !(typeid(T) is typeid(ClassProperty!int)))
119 {
120 t++; // test a few unary and binary operators
121 assert(t == 43);
122
123 t += 1;
124 assert(t == 44);
125
126 t--;
127 assert(t == 43);
128
129 t -= 1;
130 assert(t == 42);
131 }
132
133 assert(~t == ~42); // tests ComExp
134
135 return t; // tests ReturnStatement
136 }
137
138 void main()
139 {
140 assert(boolTest!(StructField!(bool))());
141 assert(boolTest!(StructProperty!(bool))());
142 assert(boolTest!(ClassField!(bool))());
143 assert(boolTest!(ClassProperty!(bool))());
144
145 assert(intTest!(StructField!(int))() == 42);
146 assert(intTest!(StructProperty!(int))() == 42);
147 assert(intTest!(ClassField!(int))() == 42);
148 assert(intTest!(ClassProperty!(int))() == 42);
149 }