Commit | Line | Data |
---|---|---|
1dcdf455 RK |
1 | /* |
2 | * This file is part of DisOrder. | |
3 | * Copyright (C) 2008 Richard Kettlewell | |
4 | * | |
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. | |
9 | * | |
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. | |
14 | * | |
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 | |
18 | * USA | |
19 | */ | |
20 | #include "test.h" | |
21 | #include "macros.h" | |
22 | ||
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; | |
28 | ||
29 | /* As simple as it gets */ | |
30 | m = mx_parse("plaintext1", 1, "", NULL); | |
31 | insist(m == 0); | |
32 | ||
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"); | |
37 | insist(m->line == 1); | |
38 | check_string(m->text, L1 L2); | |
39 | insist(m->next == 0); | |
9dbb630e | 40 | check_string(mx_dump(m), plain); |
1dcdf455 RK |
41 | |
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"); | |
46 | insist(m->line == 5); | |
47 | check_string(m->text, L1); | |
48 | insist(m->next == 0); | |
9dbb630e | 49 | check_string(mx_dump(m), L1); |
1dcdf455 RK |
50 | |
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"); | |
55 | insist(m->line == 1); | |
56 | check_string(m->name, "macro"); | |
57 | insist(m->nargs == 0); | |
58 | insist(m->args == 0); | |
59 | insist(m->next == 0); | |
9dbb630e | 60 | check_string(mx_dump(m), "@macro@"); |
1dcdf455 RK |
61 | |
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"); | |
66 | insist(m->line == 1); | |
67 | check_string(m->name, "macro"); | |
68 | insist(m->nargs == 0); | |
69 | insist(m->args == 0); | |
70 | insist(m->next == 0); | |
9dbb630e | 71 | check_string(mx_dump(m), "@macro@"); |
1dcdf455 RK |
72 | m = mx_parse("macro3", 1, "@macro @", NULL); |
73 | insist(m->type == MX_EXPANSION); | |
74 | check_string(m->filename, "macro3"); | |
75 | insist(m->line == 1); | |
76 | check_string(m->name, "macro"); | |
77 | insist(m->nargs == 0); | |
78 | insist(m->args == 0); | |
79 | insist(m->next == 0); | |
9dbb630e | 80 | check_string(mx_dump(m), "@macro@"); |
1dcdf455 RK |
81 | |
82 | /* Unterminated variants */ | |
83 | m = mx_parse("macro4", 1, "@macro", NULL); | |
84 | insist(m->type == MX_EXPANSION); | |
85 | check_string(m->filename, "macro4"); | |
86 | insist(m->line == 1); | |
87 | check_string(m->name, "macro"); | |
88 | insist(m->nargs == 0); | |
89 | insist(m->args == 0); | |
90 | insist(m->next == 0); | |
9dbb630e | 91 | check_string(mx_dump(m), "@macro@"); |
1dcdf455 RK |
92 | m = mx_parse("macro5", 1, "@macro ", NULL); |
93 | insist(m->type == MX_EXPANSION); | |
94 | check_string(m->filename, "macro5"); | |
95 | insist(m->line == 1); | |
96 | check_string(m->name, "macro"); | |
97 | insist(m->nargs == 0); | |
98 | insist(m->args == 0); | |
99 | insist(m->next == 0); | |
9dbb630e | 100 | check_string(mx_dump(m), "@macro@"); |
1dcdf455 RK |
101 | |
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); | |
110 | ||
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); | |
116 | ||
9dbb630e RK |
117 | check_string(mx_dump(m), "@macro{arg}@"); |
118 | ||
1dcdf455 RK |
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); | |
127 | ||
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); | |
133 | ||
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); | |
139 | ||
9dbb630e RK |
140 | check_string(mx_dump(m), "@macro{arg1}{arg2}@"); |
141 | ||
142 | /* Multiple bracketed arguments */ | |
1dcdf455 RK |
143 | |
144 | ||
145 | } | |
146 | ||
147 | TEST(macros); | |
148 | ||
149 | /* | |
150 | Local Variables: | |
151 | c-basic-offset:2 | |
152 | comment-column:40 | |
153 | fill-column:79 | |
154 | indent-tabs-mode:nil | |
155 | End: | |
156 | */ |