| ... | @@ -4,18 +4,18 @@ const nl = std.cstr.line_sep; | ... | @@ -4,18 +4,18 @@ const nl = std.cstr.line_sep; |
| 4 | | 4 | |
| 5 | pub fn addCases(cases: *tests.RunTranslatedCContext) void { | 5 | pub fn addCases(cases: *tests.RunTranslatedCContext) void { |
| 6 | cases.add("ternary operator", | 6 | cases.add("ternary operator", |
| 7 | \\#include <assert.h> | 7 | \\#include <stdlib.h> |
| 8 | \\static int cnt = 0; | 8 | \\static int cnt = 0; |
| 9 | \\int foo() { cnt++; return 42; } | 9 | \\int foo() { cnt++; return 42; } |
| 10 | \\int main(int argc, char **argv) { | 10 | \\int main(int argc, char **argv) { |
| 11 | \\ short q = 3; | 11 | \\ short q = 3; |
| 12 | \\ signed char z0 = q?:1; | 12 | \\ signed char z0 = q?:1; |
| 13 | \\ assert(z0 == 3); | 13 | \\ if (z0 != 3) abort(); |
| 14 | \\ int z1 = 3?:1; | 14 | \\ int z1 = 3?:1; |
| 15 | \\ assert(z1 == 3); | 15 | \\ if (z1 != 3) abort(); |
| 16 | \\ int z2 = foo()?:-1; | 16 | \\ int z2 = foo()?:-1; |
| 17 | \\ assert(z2 == 42); | 17 | \\ if (z2 != 42) abort(); |
| 18 | \\ assert(cnt == 1); | 18 | \\ if (cnt != 1) abort(); |
| 19 | \\ return 0; | 19 | \\ return 0; |
| 20 | \\} | 20 | \\} |
| 21 | , ""); | 21 | , ""); |