chibicc/test/macro.c

108 lines
1.1 KiB
C
Raw Normal View History

2020-03-30 03:30:06 +03:00
int assert(int expected, int actual, char *code);
int printf(char *fmt, ...);
int sprintf(char *buf, char *fmt, ...);
int strcmp(char *p, char *q);
int memcmp(char *p, char *q, long n);
2020-09-03 13:24:23 +03:00
#include "include1.h"
2020-03-30 03:30:06 +03:00
#
/* */ #
int main() {
2020-09-03 13:24:23 +03:00
assert(5, include1, "include1");
assert(7, include2, "include2");
2020-08-20 13:36:36 +03:00
#if 0
#include "/no/such/file"
assert(0, 1, "1");
#if nested
#endif
2020-08-20 13:36:36 +03:00
#endif
int m = 0;
#if 1
m = 5;
#endif
assert(5, m, "m");
2020-03-30 03:57:07 +03:00
#if 1
# if 0
# if 1
foo bar
# endif
# endif
m = 3;
#endif
assert(3, m, "m");
#if 1-1
# if 1
# endif
# if 1
# else
# endif
# if 0
# else
# endif
m = 2;
#else
# if 1
m = 3;
# endif
#endif
assert(3, m, "m");
#if 1
m = 2;
#else
m = 3;
#endif
assert(2, m, "m");
2020-03-29 02:51:06 +03:00
#if 1
m = 2;
#else
m = 3;
#endif
assert(2, m, "m");
#if 0
m = 1;
#elif 0
m = 2;
#elif 3+5
m = 3;
#elif 1*5
m = 4;
#endif
assert(3, m, "m");
#if 1+5
m = 1;
#elif 1
m = 2;
#elif 3
m = 2;
#endif
assert(1, m, "m");
#if 0
m = 1;
#elif 1
# if 1
m = 2;
# else
m = 3;
# endif
#else
m = 5;
#endif
assert(2, m, "m");
2020-03-30 03:30:06 +03:00
printf("OK\n");
return 0;
}