1
/* Copyright (c) 1999, 2002 Michael J. Roberts. All Rights Reserved. */
4
main.t - test source file for test_tok.exe.
6
Tests the tokenizer and preprocessor functions
10
04/17/99 MJRoberts - Creation
34
#if 1 + 2 > 8 - 5 ? 1 : 0
46
#define PRINTVAL(val) printf(#@val + '= %d\n', val)
51
"printval is defined!";
54
#if defined(UNDEFINED_SYMBOL) && defined(PRINTVAL)
55
"something's wrong!!!";
58
#if defined(DEFINITELY_NOT_DEFINED) || defined(PRINTVAL)
64
#define FILENAME "test"
66
"try string translations";
68
#pragma message("u > 7 - ok")
70
#pragma message("u not > 7 - WRONG")
74
#pragma message("\\u00C7 > aaaa - ok")
76
#pragma message("\\u00c7 not > aaaa - WRONG")
80
#pragma message("\\uC7 > \\xC6 - ok")
82
#pragma message("\\C7 not > \\xC6 - WRONG")
85
"pragma message with a translation";
86
#define TEST "this is a test message"
88
#error "macro: " TEST "!!!"
91
"try some macros with arguments";
92
#define PRODUCT(a, b) ((a) * (b))
93
#define SUM(a, b) ((a) + (b))
94
#define SUM3(a, b, c) ((a) + (b) + (c))
96
"testing product(10, 20): "; PRODUCT(10, 20);
97
"testing product(sum(10, sum3(1, 2, 3)), product(5, 10)): ";
98
PRODUCT(SUM(10, SUM3(1, 2, 3)), PRODUCT(5, 10));
100
"testing sum(sum(sum(1, 2), sum(3, 4)), sum(sum(5, 6), sum(7, 8))): ";
101
SUM(SUM(SUM(1, 2), SUM(3, 4)), SUM(SUM(5, 6), SUM(7, 8)));
103
#define CIRCULAR_A(foo) CIRCULAR_B(foo*A)
104
#define CIRCULAR_B(foo) CIRCULAR_A(foo*B)
105
"circular_a(100): "; CIRCULAR_A(100);
106
"circular_a(circular_b(50)): "; CIRCULAR_A(CIRCULAR_B(50));
108
#if SUM(1+2, 3+4) == PRODUCT(2, 5)
109
"good argument expansion";
111
"bad argument expansion";
114
#if PRODUCT(10,11) != PRODUCT(11,10)
116
#elif SUM(5 + 6, 7) == SUM3(5, 6, 7)
119
"bad else expansion";
123
"try some #if's with macro expansions";
129
#if TEST_ONE == TEST_TEN
131
#elif TEST_ONE + TEST_NINE == TEST_TEN
132
"good elif with expansion!!!";
137
#define TEST_STR_1 'abc'
138
#define TEST_STR_2 'def'
139
#define TEST_STR_3 'abc'
141
#if TEST_STR_1 < TEST_STR_2
145
#if TEST_STR_1 > TEST_STR_2
151
#if TEST_STR_1 == TEST_STR_2
153
#elif TEST_STR_1 == TEST_STR_3
157
"try some #if's with constant expressions"
166
#if 1+2*3 == (4+11)*2 - ((6+7) << 1) + (0xF03 & 03)
167
"good if!!! (and a tough one, too)";
193
"define some macros";
197
"try out a positive #if";
199
"this is a good #if";
201
"this is a bad #else";
203
"end of positive #if";
205
"try a negative #if";
209
"this is a good #else";
211
"end of negative #if";
213
"try some nested #if's";
215
"good #if - level 1"; A
217
"good #if - level 2"; B
219
"bad #if - level 3"; C
221
"good #else - level 3"; D
223
"good #if - level 2"; E
225
"bad #else - level 2"; F
227
"good #if within a bad #if -> bad - level 2"; G
229
"bad #else within bad #if -> bad - level 2"; H
230
# endif /* nested FOO */
232
"good #if - level 1"; I
234
"bad #else - level 1"; J
236
"good #if in bad else -> bad - level 2"; B
238
"bad #if in bad else -> bad - level 3"; C
240
"good #else in bad else -> bad - level 3"; D
242
"good #if in bad else -> bad - level 2"; E
244
"bad #else in bad else -> bad - level 2"; F
246
"good #if within a bad #if within bad #else -> bad - level 2"; G
248
"bad #else within bad #if within bad #else -> bad - level 2"; H
249
# endif /* nested FOO */
257
"done with nested #if's";
273
// this is a single-line comment, which should be eliminated
275
/* this is a multi-line comment on just one line */
278
* this is a full multi-line comment
282
* This is another multi-line comment. The #include that follows should
283
* be ignored, since it's part of this comment.
289
// the following #include should be ignored
290
// #include "badfile.t"
293
* the following #include should be obeyed
297
"This is a string. The #include below should be ignored,
298
because it's part of the string.
304
"This is a string with escaped \"quote marks\". Those quotes
305
shouldn't end the string.
306
\"the next #include should be ignored, since it's still part of the string:
310
That's all for the string!";
313
* here's a comment with a "string" embedded
316
"Here's a string with a /*comment*/ embedded.";
318
"Here's some mixing:" /* comment */ "String" /* comment */ "Done!!!" // EOL
322
* Include the header with a comment dangling after the end of the
325
#include "header.t" /* Start a comment here,
327
for a few lines, just to
328
make it harder. */ "<--- after the comment";
333
Line directly after the header!
336
"Try some random #line directives!";
338
#line 1234 "foo_test.c"
346
#line 1+2+3 "foo_test.c"
348
"__LINE__ and __FILE__ near the end of file: "; __LINE__, __FILE__;
350
"Make sure we come back here after we're done with an include file.";
352
>>> back from include!!! <<<
355
"Try expanding macros and calculating values in #line";
356
#line 5 + 2*LINENUM FILENAME + ".h"
358
"try __FILE__ and __LINE__";
359
"__FILE__: <<__FILE__>>, __LINE__: << __LINE__ >>\n";
365
__LINE__ >> -- that was __FILE and __LINE!\n";