The runtests script was improved so that the Java and Ruby test cases don't
[external/ragel.git] / test / high2.rl
1 /*
2  * @LANG: c++
3  */
4
5 /**
6  * Test a high character to make sure signedness 
7  * isn't messing us up.
8  */
9
10 #include <stdio.h>
11 #include <string.h>
12
13 struct Fsm
14 {
15         int cs;
16
17         // Initialize the machine. Invokes any init statement blocks. Returns 0
18         // if the machine begins in a non-accepting state and 1 if the machine
19         // begins in an accepting state.
20         int init( );
21
22         // Execute the machine on a block of data. Returns -1 if after processing
23         // the data, the machine is in the error state and can never accept, 0 if
24         // the machine is in a non-accepting state and 1 if the machine is in an
25         // accepting state.
26         int execute( const unsigned char *data, int len );
27
28         // Indicate that there is no more data. Returns -1 if the machine finishes
29         // in the error state and does not accept, 0 if the machine finishes
30         // in any other non-accepting state and 1 if the machine finishes in an
31         // accepting state.
32         int finish( );
33 };
34
35 %%{
36         machine Fsm;
37
38         alphtype unsigned char;
39
40         # Indicate we got the high character.
41         action gothigh {
42                 printf("yes\n");
43         }
44
45         main := 0xe8 @gothigh '\n';
46 }%%
47
48 %% write data;
49
50 int Fsm::init( )
51 {
52         %% write init;
53         return 0;
54 }
55
56 int Fsm::execute( const unsigned char *_data, int _len )
57 {
58         const unsigned char *p = _data;
59         const unsigned char *pe = _data+_len;
60         %% write exec;
61         if ( cs == Fsm_error )
62                 return -1;
63         if ( cs >= Fsm_first_final )
64                 return 1;
65         return 0;
66 }
67
68 int Fsm::finish()
69 {
70         %% write eof;
71         if ( cs == Fsm_error )
72                 return -1;
73         if ( cs >= Fsm_first_final )
74                 return 1;
75         return 0;
76 }
77
78 Fsm fsm;
79
80 void test( unsigned char *buf, int len )
81 {
82         fsm.init();
83         fsm.execute( buf, len );
84         if ( fsm.finish() > 0 )
85                 printf("ACCEPT\n");
86         else
87                 printf("FAIL\n");
88 }
89
90 unsigned char data1[] = { 0xe8, 10 };
91 unsigned char data2[] = { 0xf8, 10 };
92
93 int main()
94 {
95         test( data1, 2 );
96         test( data2, 2 );
97         return 0;
98 }
99
100 #ifdef _____OUTPUT_____
101 yes
102 ACCEPT
103 FAIL
104 #endif