1project('comparison', 'c')
2
3# Compare equality of strings
4
5var1 = 'foo'
6var2 = 'bar'
7
8if var1 == var2
9  exe1 = executable('broken', 'broken.c')
10else
11  exe1 = executable('prog1', 'prog.c')
12endif
13
14if var1 == var1
15  exe2 = executable('prog2', 'prog.c')
16else
17  exe2 = executable('broken', 'broken.c')
18endif
19
20if var1 != var2
21  exe3 = executable('prog3', 'prog.c')
22else
23  exe3 = executable('broken', 'broken.c')
24endif
25
26if var1 != var1
27  exe4 = executable('broken', 'broken.c')
28else
29  exe4 = executable('prog4', 'prog.c')
30endif
31
32test('equalfalse', exe1)
33test('equaltrue', exe2)
34test('nequaltrue', exe3)
35test('nequalfalse', exe4)
36
37# Non-equality comparisons
38
39var3 = 3
40var4 = 4
41
42if var3 < var4
43  exe5 = executable('prog5', 'prog.c')
44else
45  exe5 = executable('broken', 'broken.c')
46endif
47
48if var3 < var3
49  exe6 = executable('broken', 'broken.c')
50else
51  exe6 = executable('prog6', 'prog.c')
52endif
53
54if var4 > var3
55  exe7 = executable('prog7', 'prog.c')
56else
57  exe7 = executable('broken', 'broken.c')
58endif
59
60if var3 > var3
61  exe8 = executable('broken', 'broken.c')
62else
63  exe8 = executable('prog8', 'prog.c')
64endif
65
66if var4 <= var3
67  exe9 = executable('broken', 'broken.c')
68else
69  exe9 = executable('prog9', 'prog.c')
70endif
71
72if var3 <= var3
73  exe10 = executable('prog10', 'prog.c')
74else
75  exe10 = executable('broken', 'broken.c')
76endif
77
78if var3 >= var4
79  exe11 = executable('broken', 'broken.c')
80else
81  exe11 = executable('prog11', 'prog.c')
82endif
83
84if var3 >= var3
85  exe12 = executable('prog12', 'prog.c')
86else
87  exe12 = executable('broken', 'broken.c')
88endif
89
90test('lttrue', exe5)
91test('ltfalse', exe6)
92test('gttrue', exe7)
93test('gtfalse', exe8)
94test('lefalse', exe9)
95test('letrue', exe10)
96test('gefalse', exe11)
97test('getrue', exe12)
98
99# Non-elementary type comparisons
100
101if exe1 == exe2
102  exe13 = executable('broken', 'broken.c')
103else
104  exe13 = executable('prog13', 'prog.c')
105endif
106
107if exe1 == exe1
108  exe14 = executable('prog14', 'prog.c')
109else
110  exe14 = executable('broken', 'broken.c')
111endif
112
113if exe1 != exe2
114  exe15 = executable('prog15', 'prog.c')
115else
116  exe15 = executable('broken', 'broken.c')
117endif
118
119if exe1 != exe1
120  exe16 = executable('broken', 'broken.c')
121else
122  exe16 = executable('prog16', 'prog.c')
123endif
124
125test('equalfalse', exe13)
126test('equaltrue', exe14)
127test('nequaltrue', exe15)
128test('nequalfalse', exe16)
129
130# "in" and "not in" operators
131
132assert(1 in [1, 2], '''1 should be in [1, 2]''')
133assert(3 not in [1, 2], '''3 shouldn't be in [1, 2]''')
134assert(not (3 in [1, 2]), '''3 shouldn't be in [1, 2]''')
135
136assert('b' in ['a', 'b'], ''''b' should be in ['a', 'b']''')
137assert('c' not in ['a', 'b'], ''''c' shouldn't be in ['a', 'b']''')
138
139assert(exe1 in [exe1, exe2], ''''exe1 should be in [exe1, exe2]''')
140assert(exe3 not in [exe1, exe2], ''''exe3 shouldn't be in [exe1, exe2]''')
141
142assert('a' in {'a': 'b'}, '''1 should be in {'a': 'b'}''')
143assert('b' not in {'a': 'b'}, '''1 should be in {'a': 'b'}''')
144