Skip to content

Commit b4fe184

Browse files
jjtoltonclaude
andcommitted
Split codes mode tests into separate standalone file
- double_bar.pl: 29 chars mode tests using test_framework.pl - double_bar_codes.pl: 27 codes mode tests standalone (no test_framework.pl) - Defines format helpers BEFORE set_prolog_flag(double_quotes, codes) - Uses copy_term/2 to avoid variable sharing between tests - Run via CLI with -g main This avoids the issue where test_framework.pl's format("~s",...) doesn't handle character codes (only atoms), making main() fail for codes mode tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9322d19 commit b4fe184

File tree

5 files changed

+138
-150
lines changed

5 files changed

+138
-150
lines changed

src/tests/double_bar.pl

Lines changed: 0 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
:- module(double_bar_tests, []).
22

33
:- use_module(test_framework).
4-
:- discontiguous(test/2).
54

65
% Tests for the double bar || operator
76
% Based on: https://www.complang.tuwien.ac.at/ulrich/iso-prolog/double_bar
@@ -168,152 +167,3 @@
168167
L = "abc"||123,
169168
L = [a,b,c|123]
170169
)).
171-
% Tests for double bar with double_quotes set to codes
172-
% These must be in a separate section with the flag set at parse time
173-
174-
:- set_prolog_flag(double_quotes, codes).
175-
176-
test("double bar with codes mode basic", (
177-
L = "abc"||K,
178-
L = [97,98,99|K]
179-
)).
180-
181-
test("double bar with codes mode empty string", (
182-
L = ""||K,
183-
L == K
184-
)).
185-
186-
test("double bar with codes mode chain", (
187-
L = "a"||"b"||"c",
188-
L = [97,98,99]
189-
)).
190-
191-
test("double bar with codes mode unification", (
192-
"abc"||X = [97,98,99,100,101],
193-
X = [100,101]
194-
)).
195-
196-
test("double bar with codes mode mixed empty and non-empty", (
197-
L = ""||"hello"||""||world,
198-
L = [104,101,108,108,111|world]
199-
)).
200-
201-
test("double bar with codes mode with atom tail", (
202-
L = "abc"||xyz,
203-
L = [97,98,99|xyz]
204-
)).
205-
206-
207-
test("double bar with codes mode multi-line with line comment", (
208-
L = "a"|| % multiple lines
209-
"b"||
210-
"c",
211-
L = [97,98,99]
212-
)).
213-
214-
test("double bar with codes mode multi-line with block comment", (
215-
L = "a"||"b"|| /* with comments */ "c",
216-
L = [97,98,99]
217-
)).
218-
219-
test("double bar with codes mode multi-line complex", (
220-
L = "a"|| % first line
221-
"b"|| /* second */
222-
"c",
223-
L = [97,98,99]
224-
)).
225-
226-
test("double bar with codes mode spaced syntax", (
227-
L = "abc" | | K,
228-
L = [97,98,99|K]
229-
)).
230-
231-
test("double bar with codes mode spaced chain", (
232-
L = "a" | | "b" | | "c",
233-
L = [97,98,99]
234-
)).
235-
236-
test("double bar with codes mode block comment between bars", (
237-
L = "a" | /* comment */ | "b",
238-
L = [97,98]
239-
)).
240-
241-
test("double bar with codes mode line comment between bars", (
242-
L = "a" | % line comment
243-
| "b",
244-
L = [97,98]
245-
)).
246-
247-
test("double bar with codes mode block comment in spaced bar with tail", (
248-
L = "abc" |/* comment */| K,
249-
L = [97,98,99|K]
250-
)).
251-
252-
test("double bar with codes mode comment before double bar", (
253-
L = "a" /* before */ || "b",
254-
L = [97,98]
255-
)).
256-
257-
test("double bar with codes mode comment after double bar", (
258-
L = "a" || /* after */ "b",
259-
L = [97,98]
260-
)).
261-
262-
test("double bar with codes mode comment before spaced bars", (
263-
L = "a" /* before */ | | "b",
264-
L = [97,98]
265-
)).
266-
267-
test("double bar with codes mode comment after spaced bars", (
268-
L = "a" | | /* after */ "b",
269-
L = [97,98]
270-
)).
271-
272-
test("double bar with codes mode multiple comments around bars", (
273-
L = "a" /* before */ | /* between */ | /* after */ "b",
274-
L = [97,98]
275-
)).
276-
277-
test("double bar with codes mode empty at start of chain", (
278-
L = ""||"abc"||"de",
279-
L = [97,98,99,100,101]
280-
)).
281-
282-
test("double bar with codes mode empty in middle of chain", (
283-
L = "ab"||""||"cd",
284-
L = [97,98,99,100]
285-
)).
286-
287-
test("double bar with codes mode empty at end of chain", (
288-
L = "abc"||"de"||"",
289-
L = [97,98,99,100,101]
290-
)).
291-
292-
test("double bar with codes mode single character strings", (
293-
L = "x"||"y"||"z",
294-
L = [120,121,122]
295-
)).
296-
297-
test("double bar with codes mode unicode characters", (
298-
L = "α"||"β"||tail,
299-
L = [945,946|tail]
300-
)).
301-
302-
test("double bar with codes mode longer strings", (
303-
L = "hello"||"world",
304-
L = [104,101,108,108,111,119,111,114,108,100]
305-
)).
306-
307-
test("double bar with codes mode nested unification", (
308-
"a"||"b"||X = [97,98,99],
309-
X = [99]
310-
)).
311-
312-
313-
test("double bar with codes mode with numeric tail", (
314-
L = "abc"||123,
315-
L = [97,98,99|123]
316-
)).
317-
318-
319-
:- set_prolog_flag(double_quotes, chars).

src/tests/double_bar_codes.pl

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
:- use_module(library(format)).
2+
3+
run_test(Name, Goal) :-
4+
copy_term(Goal, GoalCopy),
5+
( call(GoalCopy) ->
6+
true
7+
; format("FAILED: ~q~n", [Name]),
8+
fail
9+
).
10+
11+
report_success :- format("All tests passed", []).
12+
report_failure :- format("Some tests failed", []).
13+
14+
:- set_prolog_flag(double_quotes, codes).
15+
16+
all_tests :-
17+
run_test(basic, (
18+
L = "abc"||K,
19+
L = [97,98,99|K]
20+
)),
21+
run_test(empty_string, (
22+
L = ""||K,
23+
L == K
24+
)),
25+
run_test(chain, (
26+
L = "a"||"b"||"c",
27+
L = [97,98,99]
28+
)),
29+
run_test(unification, (
30+
"abc"||X = [97,98,99,100,101],
31+
X = [100,101]
32+
)),
33+
run_test(mixed_empty, (
34+
L = ""||"hello"||""||world,
35+
L = [104,101,108,108,111|world]
36+
)),
37+
run_test(atom_tail, (
38+
L = "abc"||xyz,
39+
L = [97,98,99|xyz]
40+
)),
41+
run_test(multiline_line_comment, (
42+
L = "a"|| % multiple lines
43+
"b"||
44+
"c",
45+
L = [97,98,99]
46+
)),
47+
run_test(multiline_block_comment, (
48+
L = "a"||"b"|| /* with comments */ "c",
49+
L = [97,98,99]
50+
)),
51+
run_test(multiline_complex, (
52+
L = "a"|| % first line
53+
"b"|| /* second */
54+
"c",
55+
L = [97,98,99]
56+
)),
57+
run_test(spaced_syntax, (
58+
L = "abc" | | K,
59+
L = [97,98,99|K]
60+
)),
61+
run_test(spaced_chain, (
62+
L = "a" | | "b" | | "c",
63+
L = [97,98,99]
64+
)),
65+
run_test(block_comment_between_bars, (
66+
L = "a" | /* comment */ | "b",
67+
L = [97,98]
68+
)),
69+
run_test(line_comment_between_bars, (
70+
L = "a" | % line comment
71+
| "b",
72+
L = [97,98]
73+
)),
74+
run_test(block_comment_in_spaced_bar_with_tail, (
75+
L = "abc" |/* comment */| K,
76+
L = [97,98,99|K]
77+
)),
78+
run_test(comment_before_double_bar, (
79+
L = "a" /* before */ || "b",
80+
L = [97,98]
81+
)),
82+
run_test(comment_after_double_bar, (
83+
L = "a" || /* after */ "b",
84+
L = [97,98]
85+
)),
86+
run_test(comment_before_spaced_bars, (
87+
L = "a" /* before */ | | "b",
88+
L = [97,98]
89+
)),
90+
run_test(comment_after_spaced_bars, (
91+
L = "a" | | /* after */ "b",
92+
L = [97,98]
93+
)),
94+
run_test(multiple_comments_around_bars, (
95+
L = "a" /* before */ | /* between */ | /* after */ "b",
96+
L = [97,98]
97+
)),
98+
run_test(empty_at_start_of_chain, (
99+
L = ""||"abc"||"de",
100+
L = [97,98,99,100,101]
101+
)),
102+
run_test(empty_in_middle_of_chain, (
103+
L = "ab"||""||"cd",
104+
L = [97,98,99,100]
105+
)),
106+
run_test(empty_at_end_of_chain, (
107+
L = "abc"||"de"||"",
108+
L = [97,98,99,100,101]
109+
)),
110+
run_test(single_character_strings, (
111+
L = "x"||"y"||"z",
112+
L = [120,121,122]
113+
)),
114+
run_test(unicode_characters, (
115+
L = "α"||"β"||tail,
116+
L = [945,946|tail]
117+
)),
118+
run_test(longer_strings, (
119+
L = "hello"||"world",
120+
L = [104,101,108,108,111,119,111,114,108,100]
121+
)),
122+
run_test(nested_unification, (
123+
"a"||"b"||X = [97,98,99],
124+
X = [99]
125+
)),
126+
run_test(numeric_tail, (
127+
L = "abc"||123,
128+
L = [97,98,99|123]
129+
)).
130+
131+
main :-
132+
( all_tests ->
133+
report_success
134+
; report_failure
135+
),
136+
halt.

tests/scryer/cli/src_tests/double_bar_codes.stderr

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
All tests passed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
args = ["-f", "--no-add-history", "src/tests/double_bar_codes.pl", "-g", "main"]

0 commit comments

Comments
 (0)