From ecd4762d97cae4119cd602dafde271a77e2e5cc5 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 11 Nov 2023 13:31:51 +0100 Subject: [PATCH] Added more tests for macros --- src/test.c | 8 +++++++- src/ulas.c | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test.c b/src/test.c index 2e8ad8b..4827502 100644 --- a/src/test.c +++ b/src/test.c @@ -92,7 +92,6 @@ void test_strbuf(void) { 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"); @@ -101,6 +100,13 @@ void test_preproc(void) { 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"); } diff --git a/src/ulas.c b/src/ulas.c index 0a69688..aecc66a 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -419,6 +419,9 @@ found: 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; } @@ -488,15 +491,18 @@ int ulas_preproc(FILE *dst, FILE *src) { 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); -- 2.30.2