diff options
| author | 2026-02-23 20:36:05 +0100 | |
|---|---|---|
| committer | 2026-02-23 20:36:05 +0100 | |
| commit | 052144cabb126efe925a96f8a0597a0f2005d206 (patch) | |
| tree | 4fd87244b9eef018b30e90fdff24c5b1a145a85e /test/external/metalang99/tests/stmt.c | |
| parent | 4e9020dfb847d80475415f9f5914efaa50238767 (diff) | |
add metalang99 testsuite (preprocessor stress testing)
Diffstat (limited to 'test/external/metalang99/tests/stmt.c')
| -rw-r--r-- | test/external/metalang99/tests/stmt.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/test/external/metalang99/tests/stmt.c b/test/external/metalang99/tests/stmt.c new file mode 100644 index 0000000..cc00b1b --- /dev/null +++ b/test/external/metalang99/tests/stmt.c @@ -0,0 +1,114 @@ +#include <metalang99/stmt.h> + +#include <assert.h> + +int main(void) { + + // ML99_INTRODUCE_VAR_TO_STMT + { + if (1) + ML99_INTRODUCE_VAR_TO_STMT(int x = 5, y = 7) { + assert(5 == x); + assert(7 == y); + } + } + + // ML99_INTRODUCE_NON_NULL_PTR_TO_STMT + { + int x = 5, y = 7; + + // clang-format off + if (1) + ML99_INTRODUCE_NON_NULL_PTR_TO_STMT(int, x_ptr, &x) + ML99_INTRODUCE_NON_NULL_PTR_TO_STMT(int, y_ptr, &y) { + assert(x == *x_ptr); + assert(y == *y_ptr); + } + // clang-format on + } + + // ML99_CHAIN_EXPR_STMT + { + int x, y; + + // clang-format off + if (1) + ML99_CHAIN_EXPR_STMT(x = 1) + ML99_CHAIN_EXPR_STMT(y = 2) { + assert(1 == x); + assert(2 == y); + } + // clang-format on + + // Test -Wunused suppression via ML99_CHAIN_EXPR_STMT. + int z; + + if (1) + ML99_CHAIN_EXPR_STMT((void)z); + } + + // ML99_CHAIN_EXPR_STMT_AFTER + { + int x = 5, y = 7; + + if (1) { + assert(5 == x); + assert(7 == y); + + ML99_CHAIN_EXPR_STMT_AFTER(x = 1) { + assert(5 == x); + assert(7 == y); + + ML99_CHAIN_EXPR_STMT_AFTER(y = 2) { + assert(5 == x); + assert(7 == y); + } + + assert(5 == x); + assert(2 == y); + } + + assert(1 == x); + assert(2 == y); + } + } + + // ML99_SUPPRESS_UNUSED_BEFORE_STMT + { + int x, y; + + // clang-format off + if (1) + ML99_SUPPRESS_UNUSED_BEFORE_STMT(x) + ML99_SUPPRESS_UNUSED_BEFORE_STMT(y) + ; + // clang-format on + } + + // Clang-Format breaks with the following sequence of statements so they are put into a macro. + // clang-format off + +#define STMT_CHAINING \ + ML99_INTRODUCE_VAR_TO_STMT(int x = 5) \ + ML99_INTRODUCE_NON_NULL_PTR_TO_STMT(int, x_ptr, &x) { \ + assert(x == *x_ptr); \ + \ + ML99_CHAIN_EXPR_STMT(x = 7) \ + ML99_INTRODUCE_VAR_TO_STMT(int y = 5) \ + ML99_SUPPRESS_UNUSED_BEFORE_STMT(y) { \ + ML99_CHAIN_EXPR_STMT_AFTER(x = 123) { \ + assert(7 == x); \ + } \ + \ + assert(123 == x); \ + } \ + } + + // clang-format on + + { STMT_CHAINING } + +#undef STMT_CHAINING + + return 0; +} |