]> git.xonotic.org Git - xonotic/gmqcc.git/blob - tests/ternary.qc
test for the simple __FUNC__ case
[xonotic/gmqcc.git] / tests / ternary.qc
1 void test(float cond, float v1, float v2, float a) {
2     print(ftos(cond ? v1 : v2), " ");
3     print( (cond ? v1 : v2) ? ( (a == 1) ? "a=1"
4                               : (a == 2) ? "a=2"
5                               : "a=other"
6                               )
7                             : "not met",
8           "\n");
9 }
10
11 void select_a(float x) {
12     print("select_a: ", ftos(x), "\n");
13 }
14 void select_b(float x) {
15     print("select_b: ", ftos(x), "\n");
16 }
17
18 void main() {
19     float a, b;
20     test(0, -99, 1, 1);
21     test(0, -99, 1, 2);
22     test(0, -99, 1, 3);
23     test(0, -99, 0, 1);
24     test(0, -99, 0, 2);
25     test(0, -99, 0, 3);
26     test(1, 1, -99, 1);
27     test(1, 1, -99, 2);
28     test(1, 1, -99, 3);
29     test(1, 0, -99, 1);
30     test(1, 0, -99, 2);
31     test(1, 0, -99, 3);
32
33     b = 5;
34     a = b ? 5 : 6;
35     print(ftos(a), "\n");
36     b ? a = 9 : a = 10;
37     print(ftos(a), "\n");
38     !b ? a = 9 : a = 10;
39     print(ftos(a), "\n");
40
41     ((1) ? select_a : select_b) (1);
42     ((0) ? select_a : select_b) (0);
43 }