scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit a3bd2a62cb057fa6a7b35feba3212287ba4ccc58
parent cdfefba9cb3046798ef7eadb81785db8bff31bb5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 22 Mar 2022 09:53:57 +0100

tests/cc: Add 0200-cpp.c

Diffstat:
Atests/cc/execute/0200-cpp.c | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/cc/execute/0200-cpp.h | 1+
Mtests/cc/execute/scc-tests.lst | 1+
3 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/tests/cc/execute/0200-cpp.c b/tests/cc/execute/0200-cpp.c @@ -0,0 +1,91 @@ +/* taken from ISO/IEC 9899:1999 Section 6.10.3.5 p6 */ + +#define str(s) # s +#define xstr(s) str(s) +#define debug(s, t) test1("x" # s "= %d, x" # t "= %d", \ + x ## s, x ## t) +#define INCFILE(n) vers ## n +#define vers2 0200-cpp +#define glue(a, b) a ## b +#define xglue(a, b) glue(a, b) +#define HIGHLOW "hello" +#define LOW LOW ", world" + +int +test1(char *s, int x, int y) +{ + int i; + + for (i = 0; s[i]; i++) { + if (s[i] != "x1= %d, x2= %d"[i]) + return 0; + } + if (x + y != 3) + return 0; + return 1; +} + +int +test2(char *s1, char *s2) +{ + int i; + + for (i = 0; s1[i]; i++) { + if (s1[i] != s2[i]) + return 0; + } + return s1[i] == '\0' && s2[i] == '\0'; +} + +int +test4(char *s) +{ + int i; + + for (i = 0; s[i]; i++) { + if (s[i] != "hello"[i]) + return 0; + } + + return 1; +} + +int +test5(char *s) +{ + int i; + + for (i = 0; s[i]; i++) { + if (s[i] != "hello, world"[i]) + return 0; + } + + return 1; +} + +int +main() +{ + int x1 = 1, x2 = 2; + char *s = "strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: @\n"; + + if (!debug(1, 2)) + return 1; + + if (!test2(str(strncmp("abc\0d", "abc", '\4') // this goes away +== 0) str(: @\n), s)) + return 2; + +#include xstr(INCFILE(2).h) + + if (x != 2) + return 3; + + if (!test4(glue(HIGH, LOW))) + return 4; + + if (!test5(xglue(HIGH, LOW))) + return 5; + + return 0; +} diff --git a/tests/cc/execute/0200-cpp.h b/tests/cc/execute/0200-cpp.h @@ -0,0 +1 @@ +int x = 2; diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst @@ -190,3 +190,4 @@ 0197-cppcomment.c 0198-nullcpp.c 0199-voidpcast.c [TODO] +0200-cpp.c [TODO]