void test_preproc(void) {
TESTBEGIN("preproc");
- // should just echo back line as is
assert_preproc(" test line", 0, " test line");
assert_preproc(" 123", 0, " #define test 123\ntest");
assert_preproc("", -1, " #define 1test 123\n");
assert_preproc(" line p1 1\n line p2 2\n line p3 3 p1, p2, p3\n", 0,
"#macro test\n line $1 1\n line $2 2\n line $3 3 "
"$0\n#endmacro\ntest p1, p2, p3");
+ assert_preproc("test macro with no args\n", 0,
+ "#macro test\ntest macro with no args\n#endmacro\ntest");
+ assert_preproc("", -1, "#macro test\n not terminated\n");
+ assert_preproc(
+ "nested macro t1\nafter\ncontent n1\n\n", 0,
+ "#macro test\nnested macro $1\n#macro "
+ "nested\ncontent $1\n#endmacro\nafter\nnested n1\n#endmacro\ntest t1");
TESTEND("preproc");
}
int rc = 0;
while ((rc = ulas_preprocnext(pp, NULL, src, buf, ULAS_LINEMAX)) > 0) {
if (rc == ULAS_PPDIR_ENDMACRO) {
+ // we need to clear the line buffer to now echo back
+ // the #endmacro directive
+ pp->line.buf[0] = '\0';
break;
}
memset(buf, 0, ULAS_LINEMAX);
int rc = 0;
+ // init
struct ulas_preproc pp = {NULL, 0, ulas_str(1), ulas_str(1)};
for (size_t i = 0; i < ULAS_MACROPARAMMAX; i++) {
pp.macroparam[i] = ulas_str(8);
}
pp.macrobuf = ulas_str(8);
+ // preproc
while ((rc = ulas_preprocnext(&pp, dst, src, buf, ULAS_LINEMAX)) > 0) {
}
+ // cleanup
ulas_strfree(&pp.line);
ulas_strfree(&pp.tok);