X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=tests%2Fternary.qc;h=242a2404d54f3668a0f707f16cf7f71895250dc0;hb=4a063d3518b1af9a0c6270d5603e01d88c36c453;hp=a8e0bd73b5d037adabc8664a4405a9fd180b42a2;hpb=b966cd4f4d10f1d9550401571e24a23e774ad6ce;p=xonotic%2Fgmqcc.git diff --git a/tests/ternary.qc b/tests/ternary.qc index a8e0bd7..242a240 100644 --- a/tests/ternary.qc +++ b/tests/ternary.qc @@ -2,35 +2,45 @@ void print(...) = #1; string ftos (float) = #2; void test(float cond, float v1, float v2, float a) { - print(ftos(cond ? v1 : v2), " "); - print( (cond ? v1 : v2) ? ( (a == 1) ? "a=1" - : (a == 2) ? "a=2" - : "a=other" - ) - : "not met", - "\n"); + print(ftos(cond ? v1 : v2), " "); + print( (cond ? v1 : v2) ? ( (a == 1) ? "a=1" + : (a == 2) ? "a=2" + : "a=other" + ) + : "not met", + "\n"); +} + +void select_a(float x) { + print("select_a: ", ftos(x), "\n"); +} +void select_b(float x) { + print("select_b: ", ftos(x), "\n"); } void main() { float a, b; - test(0, -99, 1, 1); - test(0, -99, 1, 2); - test(0, -99, 1, 3); - test(0, -99, 0, 1); - test(0, -99, 0, 2); - test(0, -99, 0, 3); - test(1, 1, -99, 1); - test(1, 1, -99, 2); - test(1, 1, -99, 3); - test(1, 0, -99, 1); - test(1, 0, -99, 2); - test(1, 0, -99, 3); + test(0, -99, 1, 1); + test(0, -99, 1, 2); + test(0, -99, 1, 3); + test(0, -99, 0, 1); + test(0, -99, 0, 2); + test(0, -99, 0, 3); + test(1, 1, -99, 1); + test(1, 1, -99, 2); + test(1, 1, -99, 3); + test(1, 0, -99, 1); + test(1, 0, -99, 2); + test(1, 0, -99, 3); + + b = 5; + a = b ? 5 : 6; + print(ftos(a), "\n"); + b ? a = 9 : a = 10; + print(ftos(a), "\n"); + !b ? a = 9 : a = 10; + print(ftos(a), "\n"); - b = 5; - a = b ? 5 : 6; - print(ftos(a), "\n"); - b ? a = 9 : a = 10; - print(ftos(a), "\n"); - !b ? a = 9 : a = 10; - print(ftos(a), "\n"); + ((1) ? select_a : select_b) (1); + ((0) ? select_a : select_b) (0); }