tests.st - enscript - GNU Enscript
(HTM) git clone git://thinkerwim.org/enscript.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
tests.st (5657B)
---
1 /*
2 * States definitions file for States tests.
3 * Copyright (c) 1997 Markku Rossi.
4 * Author: Markku Rossi <mtr@iki.fi>
5 */
6
7 /*
8 * This file is part of GNU Enscript.
9 *
10 * Enscript is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Enscript is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Enscript. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 /*
25 * Initializations.
26 */
27
28 a_variable = "false";
29
30 start
31 {
32 check_startrules ();
33 check_namerules ();
34 }
35
36 startrules
37 {
38 /Test startrules\./ test_startrules;
39 }
40
41 namerules
42 {
43 /\.st$/ test_namerules;
44 }
45
46 sub ok ()
47 {
48 print ("ok");
49 }
50
51 sub fail ()
52 {
53 print ("fail");
54 }
55
56
57 /*
58 * Test states.
59 */
60
61 state skip_input
62 {
63 /[^\\\/]+/ {
64 /* NOP */
65 }
66 /./ {
67 /* NOP */
68 }
69 }
70
71 state test_startrules
72 {
73 BEGIN {
74 print ("test_startrules");
75 call (skip_input);
76 }
77 }
78
79 state test_namerules
80 {
81 BEGIN {
82 print ("test_namerules");
83 call (skip_input);
84 }
85 }
86
87 state test_optionstate
88 {
89 BEGIN {
90 print ("test_optionstate");
91 call (skip_input);
92 }
93 }
94
95 state test_first_match
96 {
97 /aaaa/ {
98 ok ();
99 call (skip_input);
100 }
101 /[ab]+/ {
102 fail ();
103 call (skip_input);
104 }
105 }
106
107 state test_case_insensitive_regexps
108 {
109 /aaaa/i {
110 ok ();
111 call (skip_input);
112 }
113 }
114
115 state test_vardef
116 {
117 BEGIN {
118 print (a_variable);
119 call (skip_input);
120 }
121 }
122
123 state test_exprs
124 {
125 BEGIN {
126
127 /* Postfix add. */
128 a = 1;
129 if (a++ != 1)
130 fail ();
131 if (a++ != 2)
132 fail ();
133 if (a++ != 3)
134 fail ();
135
136 /* Postfix sub. */
137 if (a-- != 4)
138 fail ();
139 if (a-- != 3)
140 fail ();
141 if (a-- != 2)
142 fail ();
143
144 /* Prefix add. */
145 a = 1;
146 if (++a != 2)
147 fail ();
148 if (++a != 3)
149 fail ();
150
151 /* Prefix sub. */
152 if (--a != 2)
153 fail ();
154 if (--a != 1)
155 fail ();
156
157 /* += */
158 a = 0;
159 a += 5;
160 if (a != 5)
161 fail ();
162
163 /* -= */
164 a -= 3;
165 if (a != 2)
166 fail ();
167
168 /* *= */
169 a *= 2;
170 if (a != 4)
171 fail ();
172
173 /* div= */
174 a div= 2;
175
176 if (a != 2)
177 fail ();
178
179 call (skip_input);
180 ok ();
181 }
182 }
183
184 state test_primconcat
185 {
186 BEGIN {
187 if (strcmp (concat ("a", "b", "c"), "abc") != 0)
188 fail ();
189 call (skip_input);
190 }
191 }
192
193 state test_primfloat
194 {
195 BEGIN {
196 if (float (/f/) != 0.0)
197 fail ();
198 if (float (list (1, 2, 3)) != 3.0)
199 fail ();
200 if (float ("1") != 1.0)
201 fail ();
202 if (float ("1.34") != 1.34)
203 fail ();
204 if (float ("") != 0.0)
205 fail ();
206 if (float (1) != 1.0)
207 fail ();
208 if (float (1.1) != 1.1)
209 fail ();
210 call (skip_input);
211 }
212 }
213
214 state test_primgetenv
215 {
216 BEGIN {
217 if (strcmp (getenv ("STATES_DATA"), "ok") != 0)
218 fail ();
219 call (skip_input);
220 }
221 }
222
223 state test_primint
224 {
225 BEGIN {
226 if (int (/a/) != 0)
227 fail ();
228 if (int (list (1, 2, 3, 4)) != 4)
229 fail ();
230 if (int ("1") != 1)
231 fail ();
232 if (int ("1.5") != 1)
233 fail ();
234 if (int ("") != 0)
235 fail ();
236 if (int (3) != 3)
237 fail ();
238 if (int (1.1) != 1)
239 fail ();
240 call (skip_input);
241 }
242 }
243
244 state test_primlength
245 {
246 BEGIN {
247 if (length ("ab") != 2)
248 fail ();
249 if (length (list (1, 2, "3", /4/)) != 4)
250 fail ();
251 call (skip_input);
252 }
253 }
254
255 state test_primlist
256 {
257 BEGIN {
258 lst = list (1, "2", /3/, 4);
259 if (lst[0] != 1)
260 fail ();
261 if (lst[3] != 4)
262 fail ();
263 call (skip_input);
264 }
265 }
266
267 state test_primprint
268 {
269 BEGIN {
270 print ("ok", 1, /2/);
271 call (skip_input);
272 }
273 }
274
275 state test_primregexp
276 {
277 BEGIN {
278 re = regexp (".*");
279 if (!regmatch ("abcd", re))
280 fail ();
281 call (skip_input);
282 }
283 }
284
285 state test_primregexp_syntax
286 {
287 BEGIN {
288 regexp_syntax ('-', 'w');
289 if (regmatch ("foo-bar", /\bbar\b/))
290 fail ();
291 call (skip_input);
292 }
293 }
294
295 state test_primregmatch
296 {
297 BEGIN {
298 if (!regmatch ("abcde foo bar", /[a-z]+ ([a-z]+)/))
299 fail ();
300 if (strcmp ($0, "abcde foo") != 0)
301 fail ();
302 if (strcmp ($1, "foo") != 0)
303 fail ();
304 call (skip_input);
305 }
306 }
307
308 state test_primregsub
309 {
310 BEGIN {
311 if (strcmp (regsub ("a.b.c.d", /\./, "_"), "a_b.c.d") != 0)
312 fail ();
313 call (skip_input);
314 }
315 }
316
317 state test_primregsuball
318 {
319 BEGIN {
320 if (strcmp (regsuball ("a.b.c.d", /\./, "_"), "a_b_c_d") != 0)
321 fail ();
322 call (skip_input);
323 }
324 }
325
326 state test_primsprintf
327 {
328 BEGIN {
329 str = sprintf ("%d: foo %s %.2f", 1, "bar", 1.0);
330 if (strcmp (str, "1: foo bar 1.00") != 0)
331 fail ();
332 call (skip_input);
333 }
334 }
335
336 state test_primstrcmp
337 {
338 BEGIN {
339 if (strcmp ("a", "b") != -1)
340 fail ();
341 if (strcmp ("aa", "a") != 1)
342 fail ();
343 if (strcmp ("a", "a") != 0)
344 fail ();
345 call (skip_input);
346 }
347 }
348
349 state test_primstring
350 {
351 BEGIN {
352 str = concat (string (1), string ("a"));
353 if (strcmp (str, "1a") != 0)
354 fail ();
355 call (skip_input);
356 }
357 }
358
359 state test_primstrncmp
360 {
361 BEGIN {
362 if (strncmp ("a", "ab", 1) != 0)
363 fail ();
364 if (strncmp ("aaa", "a", 2) != 1)
365 fail ();
366 call (skip_input);
367 }
368 }
369
370 state test_primsubstring
371 {
372 BEGIN {
373 if (strcmp (substring ("abcdef", 1, 3), "bc") != 0)
374 fail ();
375 call (skip_input);
376 }
377 }
378
379
380 /*
381 Local Variables:
382 mode: c
383 End:
384 */