Added a language-independent test case for the negative sense of conditions and
[external/ragel.git] / test / forder1.rl
1 /*
2  * @LANG: c
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7
8 struct forder 
9 {
10         int cs;
11 };
12
13 %%{
14         machine forder;
15         variable curstate fsm->cs;
16
17         second = 'b'
18                 >{printf("enter b1\n");}
19                 >{printf("enter b2\n");}
20         ;
21
22         first = 'a'
23                 %{printf("leave a\n");}
24                 @{printf("finish a\n");}
25         ;
26
27         main := first . second . '\n';
28 }%%
29
30 %% write data;
31
32 void forder_init( struct forder *fsm )
33 {
34         %% write init;
35 }
36
37 void forder_execute( struct forder *fsm, const char *_data, int _len )
38 {
39         const char *p = _data;
40         const char *pe = _data+_len;
41
42         %% write exec;
43 }
44
45 int forder_finish( struct forder *fsm )
46 {
47         %% write eof;
48
49         if ( fsm->cs == forder_error )
50                 return -1;
51         if ( fsm->cs >= forder_first_final )
52                 return 1;
53         return 0;
54 }
55
56 struct forder fsm;
57
58 void test( char *buf )
59 {
60         int len = strlen(buf);
61         forder_init( &fsm );
62         forder_execute( &fsm, buf, len );
63         if ( forder_finish( &fsm ) > 0 )
64                 printf("ACCEPT\n");
65         else
66                 printf("FAIL\n");
67 }
68
69 int main()
70 {
71         test( "ab\n");
72         test( "abx\n");
73         test( "" );
74
75         test(
76                 "ab\n"
77                 "fail after newline\n"
78         );
79
80         return 0;
81 }
82
83 #ifdef _____OUTPUT_____
84 finish a
85 leave a
86 enter b1
87 enter b2
88 ACCEPT
89 finish a
90 leave a
91 enter b1
92 enter b2
93 FAIL
94 FAIL
95 finish a
96 leave a
97 enter b1
98 enter b2
99 FAIL
100 #endif