Skip to content

Commit f00ca62

Browse files
committed
Add comprehensive test suite for issue #3170
Adds 78 additional test cases across three test suites to thoroughly validate the fix for issue #3170 (parser artifacts when | is declared as an operator): - issue_3170_curly: 32 tests for (|) in curly brace contexts - issue_3170_list: 21 tests for (|) in list contexts (includes valid cases) - issue_3170_nested: 25 tests for (|) in nested and mixed contexts All tests verify that (|) patterns correctly throw syntax_error when op(1105,xfy,'|') is declared, preventing silent parser artifacts.
1 parent 2451200 commit f00ca62

File tree

12 files changed

+619
-0
lines changed

12 files changed

+619
-0
lines changed
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
%% Comprehensive test cases for issue #3170
2+
%% Testing (|) patterns inside curly braces with op(1105,xfy,'|')
3+
%% All patterns should throw syntax_error, not produce artifacts
4+
5+
:- use_module(library(charsio)).
6+
:- op(1105, xfy, '|').
7+
8+
%% Category 1: Different trailing operators with ! prefix
9+
10+
test1 :-
11+
% {!*!(|)/} - original issue pattern
12+
catch(read_from_chars("{!*!(|)/}", _),
13+
error(syntax_error(_), _),
14+
true).
15+
16+
test2 :-
17+
% {!*!(|)*} - trailing multiplication
18+
catch(read_from_chars("{!*!(|)*}", _),
19+
error(syntax_error(_), _),
20+
true).
21+
22+
test3 :-
23+
% {!*!(|)+} - trailing plus
24+
catch(read_from_chars("{!*!(|)+}", _),
25+
error(syntax_error(_), _),
26+
true).
27+
28+
test4 :-
29+
% {!*!(|)-} - trailing minus
30+
catch(read_from_chars("{!*!(|)-}", _),
31+
error(syntax_error(_), _),
32+
true).
33+
34+
test5 :-
35+
% {!*!(|)//} - trailing integer division
36+
catch(read_from_chars("{!*!(|)//}", _),
37+
error(syntax_error(_), _),
38+
true).
39+
40+
test6 :-
41+
% {!*!(|)**} - trailing power
42+
catch(read_from_chars("{!*!(|)**}", _),
43+
error(syntax_error(_), _),
44+
true).
45+
46+
%% Category 2: Different prefix operators
47+
48+
test7 :-
49+
% {!+(|)/} - ! and + prefix
50+
catch(read_from_chars("{!+(|)/}", _),
51+
error(syntax_error(_), _),
52+
true).
53+
54+
test8 :-
55+
% {*!(|)/} - * prefix with ! infix
56+
catch(read_from_chars("{*!(|)/}", _),
57+
error(syntax_error(_), _),
58+
true).
59+
60+
test9 :-
61+
% {++(|)/} - double + prefix
62+
catch(read_from_chars("{++(|)/}", _),
63+
error(syntax_error(_), _),
64+
true).
65+
66+
test10 :-
67+
% {--(|)/} - double - prefix
68+
catch(read_from_chars("{--(|)/}", _),
69+
error(syntax_error(_), _),
70+
true).
71+
72+
test11 :-
73+
% {!!(|)/} - double ! prefix
74+
catch(read_from_chars("{!!(|)/}", _),
75+
error(syntax_error(_), _),
76+
true).
77+
78+
test12 :-
79+
% {+-!(|)/} - mixed prefix operators
80+
catch(read_from_chars("{+-!(|)/}", _),
81+
error(syntax_error(_), _),
82+
true).
83+
84+
%% Category 3: Multiple trailing operators
85+
86+
test13 :-
87+
% {!*!(|)///} - triple slash
88+
catch(read_from_chars("{!*!(|)///}", _),
89+
error(syntax_error(_), _),
90+
true).
91+
92+
test14 :-
93+
% {!*!(|)****} - quadruple star
94+
catch(read_from_chars("{!*!(|)****}", _),
95+
error(syntax_error(_), _),
96+
true).
97+
98+
test15 :-
99+
% {!*!(|)//*/} - mixed trailing operators
100+
catch(read_from_chars("{!*!(|)//*/}", _),
101+
error(syntax_error(_), _),
102+
true).
103+
104+
test16 :-
105+
% {!*!(|)++-} - multiple plus and minus
106+
catch(read_from_chars("{!*!(|)++-}", _),
107+
error(syntax_error(_), _),
108+
true).
109+
110+
%% Category 4: Just (|) with minimal operators
111+
112+
test17 :-
113+
% {(|)} - bare (|) in curly braces
114+
catch(read_from_chars("{(|)}", _),
115+
error(syntax_error(_), _),
116+
true).
117+
118+
test18 :-
119+
% {!(|)} - single prefix operator
120+
catch(read_from_chars("{!(|)}", _),
121+
error(syntax_error(_), _),
122+
true).
123+
124+
test19 :-
125+
% {(|)/} - single trailing operator
126+
catch(read_from_chars("{(|)/}", _),
127+
error(syntax_error(_), _),
128+
true).
129+
130+
test20 :-
131+
% {+(|)-} - single prefix and trailing
132+
catch(read_from_chars("{+(|)-}", _),
133+
error(syntax_error(_), _),
134+
true).
135+
136+
%% Category 5: Nested expressions with atoms/variables
137+
138+
test21 :-
139+
% {a*(|)+b} - atoms around (|)
140+
catch(read_from_chars("{a*(|)+b}", _),
141+
error(syntax_error(_), _),
142+
true).
143+
144+
test22 :-
145+
% {foo+(|)-bar} - named atoms
146+
catch(read_from_chars("{foo+(|)-bar}", _),
147+
error(syntax_error(_), _),
148+
true).
149+
150+
test23 :-
151+
% {X*(|)/Y} - variables around (|)
152+
catch(read_from_chars("{X*(|)/Y}", _),
153+
error(syntax_error(_), _),
154+
true).
155+
156+
test24 :-
157+
% {1+(|)*2} - numbers around (|)
158+
catch(read_from_chars("{1+(|)*2}", _),
159+
error(syntax_error(_), _),
160+
true).
161+
162+
test25 :-
163+
% {abc-(|)//xyz} - longer expressions
164+
catch(read_from_chars("{abc-(|)//xyz}", _),
165+
error(syntax_error(_), _),
166+
true).
167+
168+
%% Category 6: More complex operator combinations
169+
170+
test26 :-
171+
% {!*!*!(|)/} - extended prefix chain
172+
catch(read_from_chars("{!*!*!(|)/}", _),
173+
error(syntax_error(_), _),
174+
true).
175+
176+
test27 :-
177+
% {(|)/*/**} - complex trailing chain
178+
catch(read_from_chars("{(|)/*/**}", _),
179+
error(syntax_error(_), _),
180+
true).
181+
182+
test28 :-
183+
% {-+*!(|)+*-} - symmetric operator pattern
184+
catch(read_from_chars("{-+*!(|)+*-}", _),
185+
error(syntax_error(_), _),
186+
true).
187+
188+
%% Category 7: Edge cases with parentheses variations
189+
190+
test29 :-
191+
% {((|))/} - double parentheses
192+
catch(read_from_chars("{((|))/}", _),
193+
error(syntax_error(_), _),
194+
true).
195+
196+
test30 :-
197+
% {!(|(|))/} - nested | operator
198+
catch(read_from_chars("{!(|(|))}", _),
199+
error(syntax_error(_), _),
200+
true).
201+
202+
%% Category 8: Whitespace variations
203+
204+
test31 :-
205+
% { ! * ! ( | ) / } - with spaces
206+
catch(read_from_chars("{ ! * ! ( | ) / }", _),
207+
error(syntax_error(_), _),
208+
true).
209+
210+
test32 :-
211+
% { (|) / } - extra whitespace
212+
catch(read_from_chars("{ (|) / }", _),
213+
error(syntax_error(_), _),
214+
true).
215+
216+
%% Run all tests
217+
run :-
218+
test1, test2, test3, test4, test5, test6, test7, test8, test9, test10,
219+
test11, test12, test13, test14, test15, test16, test17, test18, test19, test20,
220+
test21, test22, test23, test24, test25, test26, test27, test28, test29, test30,
221+
test31, test32,
222+
halt.

tests/scryer/cli/issues/issue_3170_curly.stderr

Whitespace-only changes.

tests/scryer/cli/issues/issue_3170_curly.stdout

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# issue #3170 - curly brace tests
2+
# Test that (|) patterns in curly braces throw syntax_error when op(1105,xfy,'|') is declared
3+
args = ["-f", "--no-add-history", "-g", "run", "test.pl"]
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
%% Test cases for issue #3170: (|) patterns in LIST contexts
2+
%% When op(1105,xfy,'|') is declared, patterns like [(|)] should throw syntax_error
3+
4+
:- use_module(library(charsio)).
5+
:- op(1105,xfy,'|').
6+
7+
%% Category 1: Simple [(|)] - should FAIL
8+
test1 :-
9+
catch(
10+
read_term_from_chars("[(|)].", _, []),
11+
error(syntax_error(_), _),
12+
true
13+
).
14+
15+
%% Category 2: With other elements - should FAIL
16+
test2 :-
17+
catch(
18+
read_term_from_chars("[a,(|),b].", _, []),
19+
error(syntax_error(_), _),
20+
true
21+
).
22+
23+
test3 :-
24+
catch(
25+
read_term_from_chars("[(|),x,y].", _, []),
26+
error(syntax_error(_), _),
27+
true
28+
).
29+
30+
test4 :-
31+
catch(
32+
read_term_from_chars("[foo,(|)].", _, []),
33+
error(syntax_error(_), _),
34+
true
35+
).
36+
37+
%% Category 3: With operators - should FAIL
38+
test5 :-
39+
catch(
40+
read_term_from_chars("[!*!(|)/].", _, []),
41+
error(syntax_error(_), _),
42+
true
43+
).
44+
45+
test6 :-
46+
catch(
47+
read_term_from_chars("[+(|)*].", _, []),
48+
error(syntax_error(_), _),
49+
true
50+
).
51+
52+
test7 :-
53+
catch(
54+
read_term_from_chars("[-(|)].", _, []),
55+
error(syntax_error(_), _),
56+
true
57+
).
58+
59+
%% Category 4: Multiple (|) patterns - should FAIL
60+
test8 :-
61+
catch(
62+
read_term_from_chars("[(|),(|)].", _, []),
63+
error(syntax_error(_), _),
64+
true
65+
).
66+
67+
test9 :-
68+
catch(
69+
read_term_from_chars("[a,(|),b,(|),c].", _, []),
70+
error(syntax_error(_), _),
71+
true
72+
).
73+
74+
%% Category 5: Nested lists - should FAIL
75+
test10 :-
76+
catch(
77+
read_term_from_chars("[[{(|)}]].", _, []),
78+
error(syntax_error(_), _),
79+
true
80+
).
81+
82+
test11 :-
83+
catch(
84+
read_term_from_chars("[a,[b,(|)]].", _, []),
85+
error(syntax_error(_), _),
86+
true
87+
).
88+
89+
test12 :-
90+
catch(
91+
read_term_from_chars("[[(|)],x].", _, []),
92+
error(syntax_error(_), _),
93+
true
94+
).
95+
96+
test13 :-
97+
catch(
98+
read_term_from_chars("[[a,b],[(|)],[c,d]].", _, []),
99+
error(syntax_error(_), _),
100+
true
101+
).
102+
103+
%% Category 6: VALID cases that should WORK (normal list syntax)
104+
test14 :-
105+
read_term_from_chars("[a|b].", Term, []),
106+
Term = [a|b].
107+
108+
test15 :-
109+
read_term_from_chars("[1,2,3|Rest].", Term, []),
110+
Term = [1,2,3|Rest].
111+
112+
test16 :-
113+
read_term_from_chars("[x,y|[]].", Term, []),
114+
Term = [x,y].
115+
116+
test17 :-
117+
read_term_from_chars("[a|[b|[c|[]]]].", Term, []),
118+
Term = [a,b,c].
119+
120+
test18 :-
121+
read_term_from_chars("[[1,2]|[[3,4]|[]]].", Term, []),
122+
Term = [[1,2],[3,4]].
123+
124+
test19 :-
125+
read_term_from_chars("[foo(a,b)|tail].", Term, []),
126+
Term = [foo(a,b)|tail].
127+
128+
%% Additional edge cases - should FAIL
129+
test20 :-
130+
catch(
131+
read_term_from_chars("[(|)|tail].", _, []),
132+
error(syntax_error(_), _),
133+
true
134+
).
135+
136+
test21 :-
137+
catch(
138+
read_term_from_chars("[head|(|)].", _, []),
139+
error(syntax_error(_), _),
140+
true
141+
).
142+
143+
%% Run all tests
144+
run :-
145+
test1, test2, test3, test4, test5, test6, test7, test8, test9, test10,
146+
test11, test12, test13, test14, test15, test16, test17, test18, test19, test20,
147+
test21,
148+
halt.

tests/scryer/cli/issues/issue_3170_list.stderr

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
% Warning: singleton variables Rest at line 108 of test.pl
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# issue #3170 - list tests
2+
# Test that (|) patterns in list contexts throw syntax_error when op(1105,xfy,'|') is declared
3+
args = ["-f", "--no-add-history", "-g", "run", "test.pl"]

0 commit comments

Comments
 (0)