Skip to content

Commit dd25332

Browse files
committed
Migrate tests to proper three-layer format per TESTING_GUIDE.md
Replace ad-hoc issue_3172_*.in tests with proper test framework integration: - Add iso_syntax_errors.pl: Tests for ISO TC2 C.2 bar operator restrictions (single bar in parens, list notation without head/tail, op restrictions) - Add double_bar_syntax_errors.pl: Tests for WG17 2025 || operator (only valid after double-quoted string per ISO 6.3.7) - Add CLI test config for double_bar_syntax_errors - Remove old issue_3172_brackets/doublebar/operator_bar test directories Tests now follow the standard test_framework.pl pattern with test/2 predicates and main_quiet/1 for CI integration.
1 parent af5fb3a commit dd25332

16 files changed

+229
-263
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
:- module(double_bar_syntax_errors_tests, []).
2+
:- use_module(test_framework).
3+
:- use_module(library(charsio)).
4+
5+
% WG17 2025 double bar syntax error tests
6+
% Reference: https://www.complang.tuwien.ac.at/ulrich/iso-prolog/double_bar
7+
% The || operator only valid directly after double-quoted string token
8+
% term = double quoted list, bar, bar, term ;
9+
10+
% Invalid || usage - list before || violates WG17 grammar
11+
% ISO 6.3.5: [] is list notation, not double quoted list (6.3.7)
12+
13+
test("[]||X list before || should error", (
14+
catch(
15+
(read_from_chars("[]||X.", _), false),
16+
error(syntax_error(_), _),
17+
true
18+
)
19+
)).
20+
21+
test("[a,b]||X non-empty list before || should error", (
22+
catch(
23+
(read_from_chars("[a,b]||X.", _), false),
24+
error(syntax_error(_), _),
25+
true
26+
)
27+
)).
28+
29+
test("X||[] variable before || should error", (
30+
% ISO 6.3.2: Variables have priority 0, are not double quoted lists
31+
catch(
32+
(read_from_chars("X||[].", _), false),
33+
error(syntax_error(_), _),
34+
true
35+
)
36+
)).
37+
38+
test("foo||X atom before || should error", (
39+
% ISO 6.3.1.3: Atoms are atomic terms, not double quoted lists
40+
catch(
41+
(read_from_chars("foo||X.", _), false),
42+
error(syntax_error(_), _),
43+
true
44+
)
45+
)).
46+
47+
test("123||X number before || should error", (
48+
% ISO 6.3.1.1: Numbers are atomic terms, not double quoted lists
49+
catch(
50+
(read_from_chars("123||X.", _), false),
51+
error(syntax_error(_), _),
52+
true
53+
)
54+
)).
55+
56+
test("{foo||bar} atoms in curly brackets should error", (
57+
% ISO 6.3.6: {term} wraps term, but foo is atom not double-quoted string
58+
catch(
59+
(read_from_chars("{foo||bar}.", _), false),
60+
error(syntax_error(_), _),
61+
true
62+
)
63+
)).
64+
65+
test("[[]||X] nested list context should error", (
66+
catch(
67+
(read_from_chars("[[]||X].", _), false),
68+
error(syntax_error(_), _),
69+
true
70+
)
71+
)).
72+
73+
test("{[]||!} list before || in curly should error", (
74+
catch(
75+
(read_from_chars("{[]||!}.", _), false),
76+
error(syntax_error(_), _),
77+
true
78+
)
79+
)).

src/tests/iso_syntax_errors.pl

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
:- module(iso_syntax_errors_tests, []).
2+
:- use_module(test_framework).
3+
:- use_module(library(charsio)).
4+
5+
% ISO/IEC 13211-1 Technical Corrigendum 2, Section C2
6+
% See https://www.complang.tuwien.ac.at/ulrich/iso-prolog/dtc2#C2
7+
8+
test("single_bar_in_parens_should_error", (
9+
% see https://github.com/mthom/scryer-prolog/issues/3140
10+
% (|) should cause a syntax error when | is declared as an operator
11+
% ISO TC2 C.2: | cannot be both operator and head-tail separator
12+
op(1105, xfy, '|'),
13+
catch(
14+
(read_from_chars("(|).", _), false),
15+
error(syntax_error(_), _),
16+
true
17+
),
18+
op(0, xfy, '|')
19+
)).
20+
21+
test("op_create_empty_curly_should_error", (
22+
catch(
23+
op(500, xfy, {}),
24+
error(permission_error(create, operator, {}), _),
25+
true
26+
)
27+
)).
28+
29+
test("op_create_empty_curly_in_list_should_error", (
30+
catch(
31+
op(500, xfy, [{}]),
32+
error(permission_error(create, operator, {}), _),
33+
true
34+
)
35+
)).
36+
37+
test("op_create_bar_priority_1000_should_error", (
38+
catch(
39+
op(1000, xfy, '|'),
40+
error(permission_error(create, operator, '|'), _),
41+
true
42+
)
43+
)).
44+
45+
test("op_create_bar_in_list_priority_1000_should_error", (
46+
catch(
47+
op(1000, xfy, ['|']),
48+
error(permission_error(create, operator, '|'), _),
49+
true
50+
)
51+
)).
52+
53+
test("op_create_bar_prefix_should_error", (
54+
catch(
55+
op(1150, fx, '|'),
56+
error(permission_error(create, operator, '|'), _),
57+
true
58+
)
59+
)).
60+
61+
test("op_create_bar_priority_1105_should_succeed", (
62+
op(1105, xfy, '|'),
63+
% Clean up
64+
op(0, xfy, '|')
65+
)).
66+
67+
test("op_remove_bar_should_succeed", (
68+
op(1105, xfy, '|'),
69+
op(0, xfy, '|')
70+
)).
71+
72+
% ISO/IEC 13211-1:1995 §6.3.5: List notation tests
73+
% items = arg, ht_sep, arg | arg, comma, items | arg
74+
% The head-tail separator requires arg on BOTH sides
75+
76+
test("[|] without head element should error", (
77+
% [|] has no arg before the head-tail separator
78+
catch(
79+
(read_from_chars("[|].", _), false),
80+
error(syntax_error(_), _),
81+
true
82+
)
83+
)).
84+
85+
test("[|X] no head before separator should error", (
86+
% Cannot have ht_sep as first element in items
87+
catch(
88+
(read_from_chars("[|X].", _), false),
89+
error(syntax_error(_), _),
90+
true
91+
)
92+
)).
93+
94+
test("[a,|] no tail after separator should error", (
95+
% "arg, ht_sep, arg" requires arg after ht_sep too
96+
catch(
97+
(read_from_chars("[a,|].", _), false),
98+
error(syntax_error(_), _),
99+
true
100+
)
101+
)).
102+
103+
% ISO/IEC 13211-1:1995 §6.3.4: Operator notation tests
104+
% Infix operators (xfy) require operands on both sides
105+
106+
test("(|) as functor argument should error", (
107+
% ISO 6.3.3.1: arg = atom (if operator) | term (priority <= 999)
108+
% (|) is neither a valid atom argument nor a valid term
109+
op(1105, xfy, '|'),
110+
catch(
111+
(read_from_chars("_/_(|).", _), false),
112+
error(syntax_error(_), _),
113+
true
114+
),
115+
op(0, xfy, '|')
116+
)).
117+
118+
test("(|) in curly brackets should error", (
119+
% {!*!(|)*} - (|) without operands inside expression
120+
op(1105, xfy, '|'),
121+
catch(
122+
(read_from_chars("{!*!(|)*}.", _), false),
123+
error(syntax_error(_), _),
124+
true
125+
),
126+
op(0, xfy, '|')
127+
)).
128+
129+
% Valid patterns should succeed
130+
131+
test("a|b valid infix operator usage", (
132+
op(1105, xfy, '|'),
133+
read_from_chars("a|b.", T),
134+
op(0, xfy, '|'),
135+
T == '|'(a, b)
136+
)).
137+
138+
test("[a|b] valid list head-tail notation", (
139+
read_from_chars("[a|b].", T),
140+
T == [a|b]
141+
)).
142+
143+
test("{a|b} operator inside curly brackets", (
144+
op(1105, xfy, '|'),
145+
read_from_chars("{a|b}.", T),
146+
op(0, xfy, '|'),
147+
T == '{}'('|'(a, b))
148+
)).

tests/scryer/cli/issues/issue_3172_brackets.in/test.pl

Lines changed: 0 additions & 55 deletions
This file was deleted.

tests/scryer/cli/issues/issue_3172_brackets.stdout

Whitespace-only changes.

tests/scryer/cli/issues/issue_3172_brackets.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/scryer/cli/issues/issue_3172_doublebar.in/test.pl

Lines changed: 0 additions & 109 deletions
This file was deleted.

tests/scryer/cli/issues/issue_3172_doublebar.stderr

Whitespace-only changes.

tests/scryer/cli/issues/issue_3172_doublebar.stdout

Whitespace-only changes.

0 commit comments

Comments
 (0)