File: test_balanced.t

package info (click to toggle)
libregexp-common-perl 2024080801-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,328 kB
  • sloc: perl: 17,842; makefile: 2
file content (178 lines) | stat: -rwxr-xr-x 3,363 bytes parent folder | download | duplicates (4)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# VOODOO LINE-NOISE
my($C,$M,$P,$N,$S);END{print"1..$C\n$M";print"\nfailed: $N\n"if$N}
sub ok{$C++; $M.= ($_[0]||!@_)?"ok $C\n":($N++,"not ok $C (".
((caller 1)[1]||(caller 0)[1]).":".((caller 1)[2]||(caller 0)[2]).")\n")}
sub try{$P=qr/^$_[0]$/}sub fail{ok($S=$_[0]!~$P)}sub pass{ok($S=$_[0]=~$P)}

# LOAD

use Regexp::Common;
ok;

# SIMPLE BALANCING ACT

try $RE{balanced};

pass "()";
pass "(a)";
pass "(a b)";
pass "(a()b)";
pass "(a( )b)";
pass "(a(b))";
pass "(a(b)(c)(d(e)))";
pass "(a(])b)";
pass "(a({{{)b)";
fail "(";
fail "(a";
fail "(a(b)";
fail "(a( b)";
fail "(a(]b)";
fail "(a({{{)b";


# MULTIPLE BALANCING ACT

try $RE{balanced}{-parens=>"()[]"};

pass "()";
pass "(a)";
pass "(a b)";
pass "(a()b)";
pass "(a( )b)";
pass "(a(b))";
pass "(a(b)(c)(d(e)))";
pass "(a(})b)";
pass "(a([[()]])b)";
fail "(";
fail "(a";
fail "(a(b)";
fail "(a( b)";
fail "(a(]b)";
fail "(a([[[)b";


try $RE{balanced}{-begin => 'begin'}{-end => 'end'};

pass 'begin end';
fail 'begin en';
fail 'begin nd';
pass 'begin begin end end';
pass 'beginend';
pass 'beginbeginbeginendendend';
pass 'begin begin end begin begin end begin end end end';
fail 'begin begin end begin  egin end begin end end end';
fail 'begin end begin end';

try $RE{balanced}{-begin => 'start'}{-end => 'stop'};

pass 'start stop';
fail 'start st';
fail 'start op';
pass 'start start stop stop';
pass 'startstop';
pass 'startstartstartstopstopstop';
pass 'start start stop start start stop start stop stop stop';
fail 'start start stop start  tart stop start stop stop stop';
fail 'start stop start stop';

try $RE{balanced}{-parens => '()[]'}{-begin => 'start'}{-end => 'stop'};

pass 'start stop';
fail 'start st';
fail 'start op';
pass 'start start stop stop';
pass 'startstop';
pass 'startstartstartstopstopstop';
pass 'start start stop start start stop start stop stop stop';
fail 'start start stop start  tart stop start stop stop stop';
fail 'start stop start stop';

try $RE{balanced}{-begin => 'S'}{-end => 'T'};

pass 'S T';
fail 'S Q';
pass 'S S T T';
pass 'ST';
pass 'SSSTTT';
pass 'S S T S S T S T T T';
fail 'S S T S Q T S T T T';
fail 'S T S T';

try $RE{balanced}{-start => "(|["}{-end => ")|]"};

pass "()";
pass "(a)";
pass "(a b)";
pass "(a()b)";
pass "(a( )b)";
pass "(a(b))";
pass "(a(b)(c)(d(e)))";
pass "(a(})b)";
pass "(a([[()]])b)";
fail "(";
fail "(a";
fail "(a(b)";
fail "(a( b)";
fail "(a(]b)";
fail "(a([[[)b";

# Test '|' delimiters.

try $RE{balanced}{-begin => '\|'}{-end => '-'};

pass '| -';
fail '| Q';
pass '| | - -';
pass '|-';
pass '|||---';
pass '| | - | | - | - - -';
fail '| | - | Q - | - - -';
fail '| - | -';

try $RE{balanced}{-begin => '!'}{-end => '\|'};

pass '! |';
fail '! Q';
pass '! ! | |';
pass '!|';
pass '!!!|||';
pass '! ! | ! ! | ! | | |';
fail '! ! | ! Q | ! | | |';
fail '! | ! |';

try $RE{balanced}{-begin => '\||['} {-end => ')|]'};

pass "|)";
pass "|a)";
pass "|a b)";
pass "|a|)b)";
pass "|a| )b)";
pass "|a|b))";
pass "|a|b)|c)|d|e)))";
pass "|a|})b)";
pass "|a|[[|)]])b)";
fail "|";
fail "|a";
fail "|a|b)";
fail "|a| b)";
fail "|a|]b)";
fail "|a|[[[)b";

try $RE{balanced}{-begin => '(|['}{-end => ']'};

pass "(]";
pass "(a]";
pass "(a b]";
pass "(a(]b]";
pass "(a( ]b]";
pass "(a(b]]";
pass "(a(b](c](d(e]]]";
pass "(a(}]b]";
pass "(a([[(]]]]b]";
fail "(";
fail "(a";
fail "(a(b]";
fail "(a( b]";
pass "(a(]b]";
fail "(a([[[]b";