From c617bac5ba2c520255597c36a9e25f8ae704cfd0 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 4 May 2008 12:38:17 +0100 Subject: [PATCH] Further macro expansion tests + fixes. Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/macros.c | 7 ++++--- lib/t-macros.c | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/macros.c b/lib/macros.c index d5786a0..98e1436 100644 --- a/lib/macros.c +++ b/lib/macros.c @@ -557,13 +557,13 @@ int mx_expand_file(const char *path, * @param h Hash mapping argument names to argument values * @return Rewritten parse tree */ -static const struct mx_node *mx__rewrite(const struct mx_node *m, +static const struct mx_node *mx__rewrite(const struct mx_node *definition, hash *h) { - const struct mx_node *head = 0, **tailp = &head, *argvalue, *mm; + const struct mx_node *head = 0, **tailp = &head, *argvalue, *m, *mm; struct mx_node *nm; int n; - for(; m; m = m->next) { + for(m = definition; m; m = m->next) { switch(m->type) { case MX_TEXT: nm = xmalloc(sizeof *nm); @@ -596,6 +596,7 @@ static const struct mx_node *mx__rewrite(const struct mx_node *m, * values according to h. */ nm = xmalloc(sizeof *nm); *nm = *m; + nm->args = xcalloc(nm->nargs, sizeof (struct mx_node *)); for(n = 0; n < nm->nargs; ++n) nm->args[n] = mx__rewrite(m->args[n], h); nm->next = 0; diff --git a/lib/t-macros.c b/lib/t-macros.c index c246ee5..79c430e 100644 --- a/lib/t-macros.c +++ b/lib/t-macros.c @@ -182,7 +182,7 @@ static void test_macros(void) { check_integer(mx_expandstr(m, &s, 0/*u*/, NAME), 0); \ if(s && strcmp(s, OUTPUT)) { \ fprintf(stderr, "%s:%d: test %s\n" \ - " INPUT: %s\n" \ + " INPUT:\n%s\n" \ " EXPECTED: '%s'\n" \ " GOT: '%s'\n", \ __FILE__, __LINE__, NAME, INPUT, OUTPUT, s); \ @@ -260,6 +260,21 @@ static void test_macros(void) { check_macro("macro1", "@define{m}{a b c}{@c@ @b@ @a@}@" "@m{1}{2}{3}", "3 2 1"); + check_macro("macro2", "@m{b}{c}{a}", + "a c b"); + check_macro("macro3", "@m{@eq{z}{z}}{p}{q}", + "q p true"); + check_macro("macro4", + "@discard{\n" + " @define{n}{a b c}\n" + " {@if{@eq{@a@}{@b@}} {@c@} {no}}\n" + "}@" + "@n{x}{y}{z}", + "no"); + check_macro("macro5", + "@n{x}{x}{z}", + "z"); + } TEST(macros); -- [mdw]