2 * This file is part of DisOrder.
3 * Copyright (C) 2008 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 static void test_macros(void) {
24 const struct mx_node *m;
25 #define L1 "this is just some\n"
26 #define L2 "plain text\n"
27 static const char plain[] = L1 L2;
29 /* As simple as it gets */
30 m = mx_parse("plaintext1", 1, "", NULL);
33 /* Almost as simple as that */
34 m = mx_parse("plaintext1", 1, plain, NULL);
35 insist(m->type == MX_TEXT);
36 check_string(m->filename, "plaintext1");
38 check_string(m->text, L1 L2);
40 check_string(mx_dump(m), plain);
42 /* Check that partial parses stop in the right place */
43 m = mx_parse("plaintext2", 5, plain, plain + strlen(L1));
44 insist(m->type == MX_TEXT);
45 check_string(m->filename, "plaintext2");
47 check_string(m->text, L1);
49 check_string(mx_dump(m), L1);
51 /* The simplest possible expansion */
52 m = mx_parse("macro1", 1, "@macro@", NULL);
53 insist(m->type == MX_EXPANSION);
54 check_string(m->filename, "macro1");
56 check_string(m->name, "macro");
57 insist(m->nargs == 0);
60 check_string(mx_dump(m), "@macro@");
62 /* Spacing variants of the above */
63 m = mx_parse("macro2", 1, "@ macro@", NULL);
64 insist(m->type == MX_EXPANSION);
65 check_string(m->filename, "macro2");
67 check_string(m->name, "macro");
68 insist(m->nargs == 0);
71 check_string(mx_dump(m), "@macro@");
72 m = mx_parse("macro3", 1, "@macro @", NULL);
73 insist(m->type == MX_EXPANSION);
74 check_string(m->filename, "macro3");
76 check_string(m->name, "macro");
77 insist(m->nargs == 0);
80 check_string(mx_dump(m), "@macro@");
82 /* Unterminated variants */
83 m = mx_parse("macro4", 1, "@macro", NULL);
84 insist(m->type == MX_EXPANSION);
85 check_string(m->filename, "macro4");
87 check_string(m->name, "macro");
88 insist(m->nargs == 0);
91 check_string(mx_dump(m), "@macro@");
92 m = mx_parse("macro5", 1, "@macro ", NULL);
93 insist(m->type == MX_EXPANSION);
94 check_string(m->filename, "macro5");
96 check_string(m->name, "macro");
97 insist(m->nargs == 0);
100 check_string(mx_dump(m), "@macro@");
102 /* Macros with a :-separated argument */
103 m = mx_parse("macro5", 1, "@macro:arg@", NULL);
104 insist(m->type == MX_EXPANSION);
105 check_string(m->filename, "macro5");
106 insist(m->line == 1);
107 check_string(m->name, "macro");
108 insist(m->nargs == 1);
109 insist(m->next == 0);
111 insist(m->args[0]->type == MX_TEXT);
112 check_string(m->args[0]->filename, "macro5");
113 insist(m->args[0]->line == 1);
114 check_string(m->args[0]->text, "arg");
115 insist(m->args[0]->next == 0);
117 check_string(mx_dump(m), "@macro{arg}@");
119 /* Multiple :-separated arguments, and spacing, and newlines */
120 m = mx_parse("macro6", 1, "@macro : \n arg1 : \n arg2@", NULL);
121 insist(m->type == MX_EXPANSION);
122 check_string(m->filename, "macro6");
123 insist(m->line == 1);
124 check_string(m->name, "macro");
125 insist(m->nargs == 2);
126 insist(m->next == 0);
128 insist(m->args[0]->type == MX_TEXT);
129 check_string(m->args[0]->filename, "macro6");
130 insist(m->args[0]->line == 2);
131 check_string(m->args[0]->text, "arg1");
132 insist(m->args[0]->next == 0);
134 insist(m->args[1]->type == MX_TEXT);
135 check_string(m->args[1]->filename, "macro6");
136 insist(m->args[1]->line == 3);
137 check_string(m->args[1]->text, "arg2");
138 insist(m->args[1]->next == 0);
140 check_string(mx_dump(m), "@macro{arg1}{arg2}@");
142 /* Multiple bracketed arguments */