Added additional test case for define with no value
authorLukas Krickl <lukas@krickl.dev>
Sat, 11 Nov 2023 18:38:58 +0000 (19:38 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 11 Nov 2023 18:38:58 +0000 (19:38 +0100)
src/test.c
src/ulas.c

index bfb418801f38e0ca1d2c1eb5f6da76e15e176887..6a77a865fa590a7c2bb4dc20e4c2b5f2484e86d3 100644 (file)
@@ -97,6 +97,7 @@ void test_preproc(void) {
 
   // define
   assert_preproc("123", 0, "  #define test 123\ntest");
+  assert_preproc("this is a", 0, "  #define test\nthis is a test");
   assert_preproc("", -1, "  #define 1test 123\n");
   assert_preproc("", -1, "  #define\n");
   assert_preproc("this is a 123 for defs", 0,
@@ -108,8 +109,8 @@ void test_preproc(void) {
 
   // macro
   assert_preproc(
-      "  line p1 1 label01,2\n  line p2 2\n  line p3 3 p1, p2, p3\n", 0,
-      "#macro test\n  line $1 1 label$$$$,$$\n  line $2 2\n  line $3 3 "
+      "  line p1 1 label01,2 3\n  line p2 2\n  line p3 3 p1, p2, p3\n", 0,
+      "#macro test\n  line $1 1 label$$$$,$$ $$\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");
index 3c7fa98def3fd2427822dacff1697a70a907fbda..5febd33bc74c2b0c6e313c5795106f82deb3959c 100644 (file)
@@ -254,6 +254,9 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
           *n -= strlen(pp->tok.buf);
           *n += val_len;
           ulas_strensr(&pp->line, (*n) + 1 + wsi);
+
+          // only remove the first white space char if the lenght of value
+          // is greater than 1, otherwise just leave it be...
           if (val_len > 1) {
             strncat(pp->line.buf, def->value + 1, val_len - 1);
           } else {