The runtests script was improved so that the Java and Ruby test cases don't
[external/ragel.git] / test / atoi3.rl
1 #
2 # @LANG: ruby
3 #
4
5 neg = false
6 val = 0
7
8 %%{
9     machine atoi3;
10     action begin {
11         neg = false;
12         val = 0;
13     }
14     action see_neg {
15         neg = true;
16     }
17     action add_digit {
18                 val = val * 10 + (fc - "0"[0]);
19     }
20     action finish {
21                 val = -1 * val if neg
22     }
23     action print {
24         puts val;
25     }
26     atoi = (('-' @ see_neg | '+') ? (digit @ add_digit) +) > begin % finish;
27     main := atoi '\n' @ print;
28 }%%
29
30 %% write data;
31
32 def run_machine( data )
33         p = 0;
34         pe = data.length
35         cs = 0
36         cs = 0
37         val = 0;
38         neg = false;
39
40         %% write init;
41         %% write exec;
42         %% write eof;
43         if  cs >= atoi3_first_final
44                 puts "ACCEPT"
45         else
46                 puts "FAIL"
47         end
48 end
49
50 inp = [
51                 "1\n",
52                 "12\n",
53                 "222222\n",
54                 "+2123\n",
55                 "213 3213\n",
56                 "-12321\n",
57                 "--123\n",
58                 "-99\n",
59                 " -3000\n",
60 ]
61
62 inp.each { |str| run_machine(str) }
63
64 =begin _____OUTPUT_____
65 1
66 ACCEPT
67 12
68 ACCEPT
69 222222
70 ACCEPT
71 2123
72 ACCEPT
73 FAIL
74 -12321
75 ACCEPT
76 FAIL
77 -99
78 ACCEPT
79 FAIL
80 =end _____OUTPUT_____