summaryrefslogtreecommitdiff
path: root/test/ragel.d/condrep1.rl
blob: 10ae8949791150a7123ec863da7ea540944b655b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* 
 * @LANG: c++
 */

#include <iostream>
#include <string.h>
using std::cout;
using std::endl;

%%{
	machine foo;

	action seen { seen += 1; }

	action init { c = 0; }
	action inc { c += 1; }
	action min { ({ c >= min; }) }
	action max { ({ c < max; }) }

	main :=
		:condstar( '.' @seen, init, inc, min, max ):
		0;

}%%

%% write data noerror;

void test( int min, int max, const char *str )
{
	int cs;
	const char *p = str;
	const char *pe = str + strlen( str ) + 1;
	int c = 0, seen = 0;

	cout << "run " << str << " " << min << " " << max << ":";

	%% write init;
	%% write exec;

	cout << " " << seen;

	if ( cs >= foo_first_final )
		cout << " success" << endl;
	else
		cout << " failure" << endl;
}

int main()
{
	test( 0, 0, "" );
	test( 0, 1, "" );
	test( 1, 1, "" );
	test( 1, 2, "" );
	test( 2, 2, "" );
	test( 2, 3, "" );

	test( 0, 0, "." );
	test( 0, 1, "." );
	test( 1, 1, "." );
	test( 1, 2, "." );
	test( 2, 2, "." );
	test( 2, 3, "." );

	test( 0, 0, ".." );
	test( 0, 1, ".." );
	test( 1, 1, ".." );
	test( 1, 2, ".." );
	test( 2, 2, ".." );
	test( 2, 3, ".." );

	test( 0, 0, "..." );
	test( 0, 1, "..." );
	test( 1, 1, "..." );
	test( 1, 2, "..." );
	test( 2, 2, "..." );
	test( 2, 3, "..." );

	test( 0, 0, "...." );
	test( 0, 1, "...." );
	test( 1, 1, "...." );
	test( 1, 2, "...." );
	test( 2, 2, "...." );
	test( 2, 3, "...." );
	return 0;
}

##### OUTPUT #####
run  0 0: 0 success
run  0 1: 0 success
run  1 1: 0 failure
run  1 2: 0 failure
run  2 2: 0 failure
run  2 3: 0 failure
run . 0 0: 0 failure
run . 0 1: 1 success
run . 1 1: 1 success
run . 1 2: 1 success
run . 2 2: 1 failure
run . 2 3: 1 failure
run .. 0 0: 0 failure
run .. 0 1: 1 failure
run .. 1 1: 1 failure
run .. 1 2: 2 success
run .. 2 2: 2 success
run .. 2 3: 2 success
run ... 0 0: 0 failure
run ... 0 1: 1 failure
run ... 1 1: 1 failure
run ... 1 2: 2 failure
run ... 2 2: 2 failure
run ... 2 3: 3 success
run .... 0 0: 0 failure
run .... 0 1: 1 failure
run .... 1 1: 1 failure
run .... 1 2: 2 failure
run .... 2 2: 2 failure
run .... 2 3: 3 failure