Initialize Tizen 2.3
[external/ragel.git] / test / cond2.rl
1 /* 
2  * @LANG: c++
3  */
4
5 #include <iostream>
6 #include <string.h>
7 using std::cout;
8 using std::endl;
9
10 %%{
11         machine foo;
12
13         action c1 {i}
14         action c2 {j}
15
16         action one { cout << "  one" << endl;}
17         action two { cout << "  two" << endl;}
18
19         main := (
20                         [a-z] |
21                         ('\n' when c1 @one)
22                 )*
23                 ('\n' when c2 @two);
24 }%%
25
26 %% write data noerror;
27
28 void test( int i, int j, const char *str )
29 {
30         int cs = foo_start;
31         const char *p = str;
32         const char *pe = str + strlen( str );
33
34         cout << "run:" << endl;
35         %% write exec;
36         if ( cs >= foo_first_final )
37                 cout << "  success" << endl;
38         else
39                 cout << "  failure" << endl;
40         cout << endl;
41 }
42
43 int main()
44 {
45         test( 0, 0, "hi\n\n" );
46         test( 1, 0, "hi\n\n" );
47         test( 0, 1, "hi\n" );
48         test( 0, 1, "hi\n\n" );
49         test( 1, 1, "hi\n" );
50         test( 1, 1, "hi\n\n" );
51         test( 1, 1, "hi\n\nx" );
52         return 0;
53 }
54
55 #ifdef _____OUTPUT_____
56 run:
57   failure
58
59 run:
60   one
61   one
62   failure
63
64 run:
65   two
66   success
67
68 run:
69   two
70   failure
71
72 run:
73   one
74   two
75   success
76
77 run:
78   one
79   two
80   one
81   two
82   success
83
84 run:
85   one
86   two
87   one
88   two
89   failure
90
91 #endif