(file) Return to tests.st CVS log (file) (dir) Up to [RizwankCVS] / testProject / source / states / tests

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

Rizwan Kassim
Powered by
ViewCVS 0.9.2