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