-
Notifications
You must be signed in to change notification settings - Fork 0
/
iso_tests.pl
6725 lines (4861 loc) · 192 KB
/
iso_tests.pl
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
:- module(iso_tests, _, [assertions, nativeprops, unittestdecls, iso_strict]).
:- doc(title, "ISO Prolog tests for Ciao").
:- doc(author, "The Ciao Development Team").
:- doc(author, "Lorea Galech (first port)").
:- doc(author, "R@'{e}my Haemmerl@'{e}").
:- doc(author, "Jos@'{e} Luis Bueno").
:- doc(author, "Jose F. Morales (fixes, rewrite)").
:- doc(module, "This module contains a collection of test assertions
for checking compliance of Ciao with the ISO Prolog standard using the
@lib{iso_strict} package. The description of each test annotates:
- the source of the test:
- `[ISO]` tests based on ISO Prolog standard document ISO+IEC+13211
- `[ISO-cor1]` tests based or modified according to Corrigenda 1
- `[ISO-cor2]` tests based or modified according to Corrigenda 2
- `[ISO-cor3]` tests based or modified according to Corrigenda 3
- `[ISO-sics]` other tests based Péter Szabó (SICStus) tests
- `[ISO-eddbali]` other tests based on A Ed-Dbali's tests
- `[ISO-ciao]` other ISO tests unique to this test suite
- `[ISO-lg]` tests based on Logtalk test suite
- the predicate or feature to be tested (e.g., a predicate, syntax, etc.)
- and the current status in Ciao:
- nothing else: works as expected
- `bug()`: The test fails but fixing it is feasible in Ciao.
- `bug(wontfix)`: The test fails but we are not considering fixing it
(without breaking some useful Ciao feature).
The tests follow (when possible) the order specified in the ISO/IEC
13211-1 document. Additionally, it contain references to the documents
as follows:
- `ISOcore#pNNN` means *ISO/IEC 13211-1:1995. Part 1: General Core* page NNN
- `ISOcor1#pNNN` means *ISO/IEC 13211-1:1995 TECHNICAL CORRIGENDUM 1* page NNN
- `ISOcor2#pNNN` means *ISO/IEC 13211-1:1995 TECHNICAL CORRIGENDUM 2* page NNN
- `ISOcor3#pNNN` means *ISO/IEC 13211-1:1995 TECHNICAL CORRIGENDUM 3* page NNN
").
% TODO:[JF] wrong utf8 support sends corrupted data, which breaks unit
% tests runnersending, uncomment the following line when fixed:
% :- compilation_fact(fixed_utf8).
% ---------------------------------------------------------------------------
%! # Auxiliary predicates (mostly for IO)
% TODO: copy of lists:sublist/2
% @var{List2} contains all the elements of @var{List1}
%:- export(sublist/2).
sublist([], _).
sublist([Element|Residue], List) :-
member(Element, List),
sublist(Residue, List).
% NOTE: default is type(text), eof_action(error)
:- discontiguous text_def/2.
write_data(txt(What), S) :-
( nonvar(What), What = def(What0), text_def(What0, Text0) -> Text = Text0
; Text = What
),
( atom(Text) -> write(S, Text)
; write_list(Text, S)
).
write_data(bin(Bytes), S) :-
put_byte_list(Bytes, S).
write_list([], _) :- !.
write_list([Head|Tail], S) :- !,
write_list(Head, S), write_list(Tail, S).
write_list(Atom, S) :-
atom(Atom), !,
write(S, Atom).
write_list(Code, S) :-
put_code(S, Code).
put_byte_list([], _).
put_byte_list([B|Bs], S) :-
put_byte(S, B),
put_byte_list(Bs, S).
% This predicate sets the stream Sc as input and closes the stream Sn
close_instreams(Sc, Sn) :-
set_input(Sc),
close(Sn).
% This predicate sets the stream Sc as output and closes the stream Sn
close_outstreams(Sc, Sn) :-
set_output(Sc),
close(Sn).
% Current output stream
curr_out(S) :- current_output(S).
% Obtain a closed output stream (for tests)
closed_outstream(S) :-
open('/tmp/tmp.out', write, S, []), close(S).
% Current input stream
curr_in(S) :- current_input(S).
% Obtain a closed input stream (for tests)
closed_instream(S) :-
F = '/tmp/tmp.in',
wr_f(F, txt('')), % make sure the file exists
open(F, read, S, []), close(S).
w_type(txt(_), text).
w_type(bin(_), binary).
wr_f_s(F, What, Opts, S) :-
w_type(What, Type),
open(F, write, S, [type(Type)|Opts]),
write_data(What, S).
wr_f(F, What) :-
wr_f_s(F, What, [], S),
close(S).
chk_out(F, What) :-
w_type(What, Type),
open(F, read, S, [type(Type)]),
( What = txt(Data) -> read_string_to_end(S, Data0)
; What = bin(Data) -> read_bytes_to_end(S, Data0)
; fail
),
close(S),
Data = Data0.
wr_and_open(F,What,Opts,S) :-
( What = txtbin(Bin) -> % write text specified as a binary, read as text
wr_f(F, bin(Bin)),
Type = text
; wr_f(F, What),
w_type(What, Type)
),
open(F, read, S, [type(Type)|Opts]).
w_in(What,prev(Sc,S)) :-
wr_and_open('/tmp/tmp.in',What,[],S),
current_input(Sc),
set_input(S).
w_in_s(What,S,prev(S)) :-
wr_and_open('/tmp/tmp.in',What,[],S).
w_in_s_e(What,S,prev(S)) :-
wr_and_open('/tmp/tmp.in',What,[eof_action(eof_code)],S).
w_in_a(What,prev(S)) :-
wr_and_open('/tmp/tmp.in',What,[alias(st_i)],S).
txt_out_s(S, prev(S)) :-
open('/tmp/tmp.out', write, S).
txt_out_a(prev(S1)) :-
open('/tmp/tmp.out', write, S1, [alias(st_o)]).
% Undo (close streams, etc)
und(prev(S2)) :- close(S2).
und(prev(Sc, Sn)) :- close_instreams(Sc, Sn).
:- meta_predicate with_def_ops(goal).
with_def_ops(Goal) :-
% TODO: refine, not all operators are needed in all tests
% TODO:[JF] split fxops and fyops
Ops = [op(100, fx, fx),
op(100, fy, fy),
op(100, xfx, xfx),
op(100, xfy, xfy),
op(100, yfx, yfx),
op(100, xf, xf),
op(100, yf, yf)],
with_ops(Ops, Goal).
% ---------------------------------------------------------------------------
% TODO: duplicated stream_utils:read_string_to_end/2; remove once stream aliases are integrated
%:- export(read_string_to_end/2).
read_string_to_end(S, L) :-
get_code(S, C),
( C = -1 -> L = []
; L = [C|L0],
read_string_to_end(S, L0)
).
read_bytes_to_end_ci(X) :-
current_input(S),
read_bytes_to_end(S, X).
%:- export(read_bytes_to_end/2).
read_bytes_to_end(S, L) :-
get_byte(S, C),
( C = -1 -> L = []
; L = [C|L0],
read_bytes_to_end(S, L0)
).
% ---------------------------------------------------------------------------
:- use_module(library(port_reify)).
:- meta_predicate with_pflag(?, ?, goal).
with_pflag(Flag, Value, G) :-
current_prolog_flag(Flag, Value0),
set_prolog_flag(Flag, Value),
once_port_reify(G, Port),
set_prolog_flag(Flag, Value0),
port_call(Port).
:- meta_predicate with_ops(?, goal).
with_ops(Ops, G) :-
set_ops(Ops),
once_port_reify(G, Port),
unset_ops(Ops),
port_call(Port).
set_ops([]).
set_ops([op(P,F,Op)|Ops]) :- op(P, F, Op), set_ops(Ops).
unset_ops([]).
unset_ops([op(_,F,Op)|ABs]) :- op(0, F, Op), unset_ops(ABs).
% NOTE: char conversion may break message passing in the unittest framework, enclose here
:- meta_predicate with_chcvs(?, goal).
with_chcvs(ChCvs, G) :-
set_char_conversions(ChCvs),
set_prolog_flag(char_conversion, on),
once_port_reify(G, Port),
set_prolog_flag(char_conversion, off),
unset_char_conversions(ChCvs),
port_call(Port).
set_char_conversions([]).
set_char_conversions([A-B|ABs]) :- char_conversion(A,B), set_char_conversions(ABs).
unset_char_conversions([]).
unset_char_conversions([A-_|ABs]) :- char_conversion(A,A), unset_char_conversions(ABs).
% TODO:[JF] factorize
:- meta_predicate with_out_s(?, ?, goal, ?).
with_out_s(What, S, G, OutWhat) :-
wr_f_s('/tmp/tmp.out', What, [], S),
once_port_reify(G, Port),
close(S),
port_call(Port),
chk_out('/tmp/tmp.out', OutWhat).
:- meta_predicate with_out(?, goal, ?).
with_out(What, G, OutWhat) :-
wr_f_s('/tmp/tmp.out', What, [], S),
current_output(Sc),
set_output(S),
once_port_reify(G, Port),
close_outstreams(Sc, S),
port_call(Port),
chk_out('/tmp/tmp.out', OutWhat).
:- meta_predicate with_out_a(?, goal, ?).
with_out_a(What, G, OutWhat) :-
wr_f_s('/tmp/tmp.out', What, [alias(st_o)], S),
once_port_reify(G, Port),
close(S),
port_call(Port),
chk_out('/tmp/tmp.out', OutWhat).
% ===========================================================================
%! # 6.3 Term syntax
% ---------------------------------------------------------------------------
%! ## 6.3.3 canonical notation ISOcore#p17
% NOTE: The standard calls this functional notation, which has nothing
% to do with fsyntax package in Ciao Prolog (JF)
:- test term_test1
+ (not_fails,
setup(w_in(txt('f(x,y).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: arguments".
term_test1 :- read(_).
:- test term_test2
+ (not_fails,
setup(w_in(txt('f(:-, ;, [:-, :-|:-]).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: arguments".
term_test2 :- read(_).
:- test term_test3
+ (setup(w_in(txt('f(,,a).'), Prev)), cleanup(und(Prev)),
exception(error(syntax_error(ImplDepAtom), _)))
# "[ISO] syntax: arguments".
term_test3 :- read(_).
:- test term_test4
+ (setup(w_in(txt('[a,,|v].'), Prev)), cleanup(und(Prev)),
exception(error(syntax_error(ImplDepAtom), _)))
# "[ISO] syntax: arguments".
term_test4 :- read(_).
:- test term_test5
+ (setup(w_in(txt('[a,b|,]'), Prev)), cleanup(und(Prev)),
exception(error(syntax_error(ImplDepAtom), _)))
# "[ISO] syntax: arguments".
term_test5 :- read(_).
:- test term_test6
+ (not_fails,
setup(w_in(txt("f(',',a)."), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: arguments".
term_test6 :- read(_).
:- test term_test7
+ (not_fails,
setup(w_in(txt("[a,','|v]."), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: arguments".
term_test7 :- read(_).
:- test term_test8
+ (not_fails,
setup(w_in(txt("[a,b|',']."), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: arguments".
term_test8 :- read(_).
% ---------------------------------------------------------------------------
%! ## 6.3.4 operator notation ISOcore#p17
:- test opnotation_test1
+ (setup(w_in(txt('fx fx 1.'), Prev)), cleanup(und(Prev)),
exception(error(syntax_error(ImplDepAtom), _)))
# "[ISO] syntax: operators".
opnotation_test1 :- with_def_ops(read(_)).
:- test opnotation_test2
+ (not_fails,
setup(w_in(txt('fx (fx 1).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: operators".
opnotation_test2 :- with_def_ops(read(_)).
:- test opnotation_test3
+ (setup(w_in(txt('1 xf xf.'), Prev)), cleanup(und(Prev)),
exception(error(syntax_error(ImplDepAtom), _)))
# "[ISO] syntax: operators".
opnotation_test3 :- with_def_ops(read(_)).
:- test opnotation_test4
+ (not_fails,
setup(w_in(txt('(1 xf) xf.'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: operators".
opnotation_test4 :- with_def_ops(read(_)).
:- test opnotation_test5
+ (setup(w_in(txt('1 xfx 2 xfx 3.'), Prev)), cleanup(und(Prev)),
exception(error(syntax_error(ImplDepAtom), _)))
# "[ISO] syntax: operators".
opnotation_test5 :- with_def_ops(read(_)).
:- test opnotation_test6
+ (not_fails,
setup(w_in(txt('(1 xfx 2) xfx 3.'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: operators".
opnotation_test6 :- with_def_ops(read(_)).
:- test opnotation_test7
+ (setup(w_in(txt('1 xfx 2 xfx 3.'), Prev)), cleanup(und(Prev)),
exception(error(syntax_error(ImplDepAtom), _)))
# "[ISO] syntax: operators".
opnotation_test7 :- with_def_ops(read(_)).
:- test opnotation_test8
+ (not_fails,
setup(w_in(txt('1 xfx (2 xfx 3).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: operators".
opnotation_test8 :- with_def_ops(read(_)).
:- test opnotation_test9(T, T1) => (T=T1)
+ (not_fails,
setup(w_in(txt('fy fy 1. fy (fy 1).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: operators".
opnotation_test9(T, T1) :- with_def_ops((read(T), read(T1))).
:- test opnotation_test10(T, T1) => (T=T1)
+ (not_fails,
setup(w_in(txt('1 xfy 2 xfy 3. 1 xfy (2 xfy 3).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: operators".
opnotation_test10(T, T1) :- with_def_ops((read(T), read(T1))).
:- test opnotation_test11(T, T1) => (T=T1)
+ (not_fails,
setup(w_in(txt('1 xfy 2 yfx 3. 1 xfy (2 yfx 3).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: operators".
opnotation_test11(T, T1) :- with_def_ops((read(T), read(T1))).
:- test opnotation_test12(T, T1) => (T=T1)
+ (not_fails,
setup(w_in(txt('fy 2 yf. fy (2 yf).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: operators".
opnotation_test12(T, T1) :- with_def_ops((read(T), read(T1))).
:- test opnotation_test13(T, T1) => (T=T1)
+ (not_fails,
setup(w_in(txt('1 yf yf. (1 yf) yf.'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: operators".
opnotation_test13(T, T1) :- with_def_ops((read(T), read(T1))).
:- test opnotation_test14(T, T1) => (T=T1)
+ (not_fails,
setup(w_in(txt('1 yfx 2 yfx 3. (1 yfx 2) yfx 3.'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: operators".
opnotation_test14(T, T1) :- with_def_ops((read(T), read(T1))).
% ---------------------------------------------------------------------------
%! ## 6.3.5 list notation ISOcore#p19
:- test list_test1(T) => (T=[a])
+ (not_fails,
setup(w_in(txt('.(a,[]).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: list notation".
list_test1(T) :- read(T).
:- test list_test2(T) => (T=[a, b])
+ (not_fails,
setup(w_in(txt('.(a, .(b,[])).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: list notation".
list_test2(T) :- read(T).
:- test list_test3(T) => (T=[a|b])
+ (not_fails,
setup(w_in(txt('.(a,b).'), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: list notation".
list_test3(T) :- read(T).
% ---------------------------------------------------------------------------
%! ## 6.3.6 curly bracketed term ISOcore#p20
:- test curly_test1(T) => (T={a})
+ (not_fails,
setup(w_in(txt("'{}'(a)."), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: @{@}/1 notation".
curly_test1(T) :- read(T).
:- test curly_test2(T) => (T={a, b})
+ (not_fails,
setup(w_in(txt("'{}'(','(a,b))."), Prev)), cleanup(und(Prev)))
# "[ISO] syntax: @{@}/1 notation".
curly_test2(T) :- read(T).
% ---------------------------------------------------------------------------
%! ## 6.3.7 double quoted list notation ISOcore#p20
% NOTE: Current issues in Ciao:
%
% - Do not trust the output of those tests until the double_quotes
% flag is implemented.
text_def(dq_ex_1, [
'( current_prolog_flag(double_quotes, chars), atom_chars(\'jim\', "jim")',
'; current_prolog_flag(double_quotes, codes), atom_codes(\'jim\', "jim")',
'; current_prolog_flag(double_quotes, atom), \'jim\' == "jim"',
').']).
text_def(dq_ex_2, [
'( current_prolog_flag(double_quotes, chars), [] == ""',
'; current_prolog_flag(double_quotes, codes), [] == ""',
'; current_prolog_flag(double_quotes, atom), \'\' == ""',
').']).
% TODO:[JF] atom_chars(X, [108]) should report error(type_error(character,108),atom_chars/2).
:- test doublequoted_test1 +
( not_fails,
setup(w_in(txt(def(dq_ex_1)), Prev)), cleanup(und(Prev)) )
# "[ISO] syntax: double quotes: bug()".
doublequoted_test1 :-
with_pflag(double_quotes, chars, (read(Goal), call(Goal))).
:- test doublequoted_test2 +
( not_fails,
setup(w_in(txt(def(dq_ex_1)), Prev)), cleanup(und(Prev)) )
# "[ISO] syntax: double quotes: bug()".
doublequoted_test2 :-
with_pflag(double_quotes, codes, (read(Goal), call(Goal))).
:- test doublequoted_test3 +
( not_fails,
setup(w_in(txt(def(dq_ex_1)), Prev)), cleanup(und(Prev)) )
# "[ISO] syntax: double quotes: bug()".
doublequoted_test3 :-
with_pflag(double_quotes, atom, (read(Goal), call(Goal))).
:- test doublequoted_test4 +
( not_fails,
setup(w_in(txt(def(dq_ex_2)), Prev)), cleanup(und(Prev)) )
# "[ISO] syntax: double quotes: bug()".
doublequoted_test4 :-
with_pflag(double_quotes, chars, (read(Goal), call(Goal))).
:- test doublequoted_test5 +
( not_fails,
setup(w_in(txt(def(dq_ex_2)), Prev)), cleanup(und(Prev)) )
# "[ISO] syntax: double quotes: bug()".
doublequoted_test5 :-
with_pflag(double_quotes, codes, (read(Goal), call(Goal))).
:- test doublequoted_test6 +
( not_fails,
setup(w_in(txt(def(dq_ex_2)), Prev)), cleanup(und(Prev)) )
# "[ISO] syntax: double quotes: bug()".
doublequoted_test6 :-
with_pflag(double_quotes, atom, (read(Goal), call(Goal))).
:- test doublequoted_test7 +
( not_fails,
setup(w_in(txt('"jim".'), Prev)), cleanup(und(Prev)) )
# "[ISO-sics] syntax: double quotes: bug()".
doublequoted_test7 :-
with_pflag(double_quotes, chars, (read(X), atom_chars('jim', X))).
:- test doublequoted_test8 +
( not_fails,
setup(w_in(txt('"jim".'), Prev)), cleanup(und(Prev)) )
# "[ISO-sics] syntax: double quotes: bug()".
doublequoted_test8 :-
with_pflag(double_quotes, codes, (read(X), atom_codes('jim', X))).
:- test doublequoted_test9 +
( not_fails,
setup(w_in(txt('"jim".'), Prev)), cleanup(und(Prev)) )
# "[ISO-sics] syntax: double quotes: bug()".
doublequoted_test9 :-
with_pflag(double_quotes, atom, (read(X), 'jim' == X)).
:- test doublequoted_test10 +
( not_fails,
setup(w_in(txt('"".'), Prev)), cleanup(und(Prev)) )
# "[ISO-sics] syntax: double quotes: bug()".
doublequoted_test10 :-
with_pflag(double_quotes, chars, (read(X), atom_chars('', X))).
:- test doublequoted_test11 +
( not_fails,
setup(w_in(txt('"".'), Prev)), cleanup(und(Prev)) )
# "[ISO-sics] syntax: double quotes: bug()".
doublequoted_test11 :-
with_pflag(double_quotes, codes, (read(X), atom_codes('', X))).
:- test doublequoted_test12 +
( not_fails,
setup(w_in(txt('"".'), Prev)), cleanup(und(Prev)) )
# "[ISO-sics] syntax: double quotes: bug()".
doublequoted_test12 :-
with_pflag(double_quotes, atom, (read(X), '' == X)).
% ===========================================================================
%! # 7.8 Control constructs
% NOTE: Current issues in Ciao:
%
% - cut (`!/0`) is illegal in `\+` or if-parts of `->`
% - The term to goal translation in `call/1` should set the right
% scope of cut (!).
% - The term to goal translation in `call/1` should complain when
% finding a non-callable and report the whole term.
%
% NOTE: Incompatibilities in Ciao:
%
% - catch_test4 seems to be wrong
%! ## 7.8.1 true/0 ISOcore#p43
:- test true + not_fails # "[ISO] true/0".
% ---------------------------------------------------------------------------
%! ## 7.8.2 fail/0 ISOcore#p44
:- test fail/0 + fails # "[ISO] fail/0".
% ---------------------------------------------------------------------------
%! ## 7.8.3 call/1 ISOcore#p45
:- test call_test1 # "[ISO] call/1".
call_test1 :- call(!).
:- test call_test2 + fails # "[ISO] call/1".
call_test2 :- call(fail).
:- test call_test3(X) + fails # "[ISO] call/1".
call_test3(X) :- call((fail, X)).
:- test call_test4 + fails # "[ISO] call/1".
call_test4 :- call((fail, call(1))).
:- test call_test5 + exception(error(instantiation_error, _)) # "[ISO] call/1".
call_test5 :- call(bb(_)).
bb(X) :-
Y=(write(X), X),
call(Y).
:- test call_test6
+ ( user_output("3"),
exception(error(type_error(callable, 3), _)) )
# "[ISO] call/1".
call_test6 :- call(bb(3)).
% TODO:[JF] set the scope of cut when the term is translated to a goal
:- test call_test7(Result) => (Result=[[1, !]])
# "[ISO] call/1: bug()".
call_test7(Result) :- findall([X, Z], (Z= !, call((Z= !, aa(X), Z))), Result).
aa(1).
aa(2).
% NOTE: It works because `call(!)` is equivalent to `true`
:- test call_test8(Result) => (Result=[[1, !], [2, !]])
# "[ISO] call/1".
call_test8(Result) :- findall([X, Z], (call((Z= !, aa(X), Z))), Result).
:- test call_test9(X)
+ (user_output("3"), exception(error(instantiation_error, _)))
# "[ISO] call/1".
call_test9(X) :- call((write(3), X)).
:- test call_test10
+ (user_output("3"),
exception(error(type_error(callable, 1), _)))
# "[ISO] call/1".
call_test10 :- call((write(3), call(1))).
:- test call_test11 + exception(error(instantiation_error, _))
# "[ISO] call/1".
call_test11 :- call(_).
:- test call_test12 + exception(error(type_error(callable, 1), _))
# "[ISO] call/1".
call_test12 :- call(1).
% TODO:[JF] complain about non-callable when the term is translated to a goal
:- test call_test13
+ exception(error(type_error(callable, (fail, 1)), _))
# "[ISO] call/1: bug()".
call_test13 :- call((fail, 1)).
% TODO:[JF] complain about non-callable when the term is translated to a goal,
% do not write anything to output!
:- test call_test14
+ exception(error(type_error(callable, (write(3), 1)), _))
# "[ISO] call/1: bug()".
call_test14 :- call((write(3), 1)).
% TODO:[JF] it should complain about non-callable when the term is translated to a goal,
% and report the whole goal
:- test call_test15 + exception(error(type_error(callable, (1;true)), _))
# "[ISO] call/1: bug()".
call_test15 :- call((1;true)).
% TODO:[JF] it should complain about non-callable when the term is translated to a goal,
% instead it executes the first branch
:- test call_test16 + exception(error(type_error(callable, (true;1)), _))
# "[ISO-ciao] call/1: bug()".
call_test16 :- call((true;1)).
% ---------------------------------------------------------------------------
%! ## 7.8.4 !/0 ISOcore#p46
:- test cut_test1
# "[ISO] cut".
cut_test1 :- !.
:- test cut_test2/0 + fails
# "[ISO] cut".
cut_test2 :- !, fail;true.
:- test cut_test3/0
# "[ISO] cut".
cut_test3 :- call(!), fail;true.
:- test cut_test4/0 + (user_output("C Forwards "), fails)
# "[ISO] cut".
cut_test4 :- twice(_), !, write('Forwards '), fail.
:- test cut_test5 + (user_output("Cut disjunction"), fails)
# "[ISO] cut".
cut_test5 :- (! ; write('No ')), write('Cut disjunction'), fail.
:- test cut_test6 + (user_output("C No Cut Cut "), fails)
# "[ISO] cut".
cut_test6 :- twice(_), (write('No ') ; !), write('Cut '), fail.
:- test cut_test7 + (user_output("C "), fails)
# "[ISO] cut".
cut_test7 :- twice(_), (!, fail, write('No ')).
:- test cut_test8 + (user_output("C Forwards Moss Forwards "), fails)
# "[ISO] cut".
cut_test8 :- twice(X), call(X), write('Forwards '), fail.
:- test cut_test9 + (user_output("C Forwards Three Forwards "), fails)
# "[ISO] cut".
cut_test9 :- goal(X), call(X), write('Forwards '), fail.
% TODO:[JF] ! is illegal in \+ or if-parts of ->; uncomment when fixed
:- test cut_test10
+ (user_output("C Forwards Moss Forwards "),fails)
# "[ISO] cut: bug()".
% cut_test10 :- twice(_), (\+(\+(!))), write('Forwards '), fail.
cut_test10 :- throw(bug).
:- test cut_test11 + (user_output("C Forwards Moss Forwards "), fails)
# "[ISO] cut".
cut_test11 :- twice(_), once(!), write('Forwards '), fail.
:- test cut_test12 + (user_output("C Forwards Moss Forwards "), fails)
# "[ISO] cut".
cut_test12 :- twice(_), call(!), write('Forwards '), fail.
% TODO:[JF] ! illegal in -> part ; reimplement without findall/3 when fixed
:- test cut_test13 + not_fails
# "[ISO-ciao] cut: bug()".
cut_test13 :-
findall(Y, ( member(X,[1,2]), !, X=2 -> Y=a ; Y=b ), Ys),
Ys = [b].
% ---------------------------------------------------------------------------
% (these predicates are used in the tests above)
twice(!) :- write('C ').
twice(true) :- write('Moss ').
goal((twice(_), !)).
goal(write('Three ')).
% ---------------------------------------------------------------------------
%! ## 7.8.5 (,)/2 ISOcore#p47
:- test and_test1 + fails
# "[ISO] ','".
and_test1 :- ','(X=1, var(X)).
:-test and_test2(X) => (X=1)
# "[ISO] ','".
and_test2(X) :- ','(var(X), X=1).
:- test and_test3(X) => (X=true)
# "[ISO] ','".
and_test3(X) :- ','(X=true, call(X)).
% ---------------------------------------------------------------------------
%! ## 7.8.6 (;)/2 ISOcore#p48
:- test or_test1
# "[ISO] ';'".
or_test1 :- ';'(true, fail).
:- test or_test2 + fails
# "[ISO] ';'".
or_test2 :- ';'((!, fail), true).
:- test or_test3
# "[ISO] ';'".
or_test3 :- ';'(!, call(3)).
:- test or_test4(X) => (X=1)
# "[ISO] ';'".
or_test4(X) :- ';'((X=1, !), X=2).
:- test or_test5(Result) => (Result=[1, 1])
# "[ISO] ';'".
or_test5(Result) :- findall(X, call((;(X=1, X=2), ;(true, !))), Result).
% ---------------------------------------------------------------------------
%! ## 7.8.7 (->)/2 if-then ISOcore#p49
:- test ifthen_test1
# "[ISO] '->'".
ifthen_test1 :- '->'(true, true).
:- test ifthen_test2 + fails
# "[ISO] '->'".
ifthen_test2:- '->'(true, fail).
:- test ifthen_test3 + fails
# "[ISO] '->'".
ifthen_test3 :- '->'(fail, true).
:- test ifthen_test4(Result) => (Result=[1])
# "[ISO] '->'".
ifthen_test4(Result) :- findall(X, '->'(true, X=1), Result).
:- test ifthen_test5(Result) => (Result=[1])
# "[ISO] '->'".
ifthen_test5(Result) :- findall(X, '->'(';'(X=1, X=2), true), Result).
:- test ifthen_test6(Result) => (Result=[1, 2])
# "[ISO] '->'".
ifthen_test6(Result) :- findall(X, '->'(true, ';'(X=1, X=2)), Result).
% ===========================================================================
%! ## 7.8.8 (;)/2 if-then-else ISOcore#p51
:- test ifthenelse_test1
# "[ISO] if-then-else".
ifthenelse_test1 :- ';'('->'(true, true), fail).
:- test ifthenelse_test2
# "[ISO] if-then-else".
ifthenelse_test2 :- ';'('->'(fail, true), true).
:- test ifthenelse_test3 + fails
# "[ISO] if-then-else".
ifthenelse_test3 :- ';'('->'(true, fail), fail).
:- test ifthenelse_test4 + fails
# "[ISO] if-then-else".
ifthenelse_test4 :- ';'('->'(fail, true), fail).
:- test ifthenelse_test5(X) => (X=1)
# "[ISO] if-then-else".
ifthenelse_test5(X) :- ';'('->'(true, X=1), X=2).
:- test ifthenelse_test6(X) => (X=2)
# "[ISO] if-then-else".
ifthenelse_test6(X) :- ';'('->'(fail, X=1), X=2).
:- test ifthenelse_test7(Result) => (Result=[1, 2])
# "[ISO] if-then-else".
ifthenelse_test7(Result) :-
findall(X, ';'('->'(true, ';'(X=1, X=2)), true), Result).
:- test ifthenelse_test8(X) => (X=1)
# "[ISO] if-then-else".
ifthenelse_test8(X) :- ';'('->'(';'(X=1, X=2), true), true).
% TODO:[JF] ! is illegal in \+ or if-parts of ->; uncomment when fixed
:- test ifthenelse_test9
+ not_fails
# "[ISO] if-then-else".
% ifthenelse_test9 :- ';'('->'(','(!, fail), true), true).
ifthenelse_test9 :- throw(bug).
% ---------------------------------------------------------------------------
%! ## 7.8.9 catch/3 ISOcore#p52
:- test catch_test1(Y) => (Y=10)
# "[ISO] catch/3".
catch_test1(Y) :- catch(p_catch__foo(5), test(Y), true).
p_catch__foo(X) :- Y is X*2, throw(test(Y)).
:- test catch_test2(Z) : (Z=3)
# "[ISO] catch/3".
catch_test2(Z) :- catch(p_catch__bar(3), Z, true).
p_catch__bar(X) :- X = Y, throw(Y).
:- test catch_test3
# "[ISO] catch/3".
catch_test3 :- catch(true, _, 3).
% TODO:[JF] this ISO tests seems to be wrong (according to all Prolog systems and Logtalk)
% :- test catch_test4 + exception(error(system_error, _))
% # "[ISO] catch/3".
%
% catch_test4 :- catch(true, _C, write(demoen)), throw(bla).
:- test catch_test5(Y) => (Y=1)
# "[ISO] catch/3".
catch_test5(Y) :- catch(p_catch__car(_X), Y, true).
p_catch__car(X) :- X=1, throw(X).
:- test catch_test6 + fails
# "[ISO] catch/3".
catch_test6 :-
catch(number_chars(_X, ['1', 'a', '0']), error(syntax_error(_), _), fail).
:- test catch_test7(Result) => (Result=[c]) + (user_output("h1"))
# "[ISO] catch/3".
catch_test7(Result) :- findall(C, catch(p_catch__g, C, write(h1)), Result).
p_catch__g :- catch(p_catch__p, _B, write(h2)), p_catch__coo(c).
p_catch__p.
p_catch__p :- throw(b).
p_catch__coo(X) :- throw(X).
:- test catch_test8(Y) => (Y=error(instantiation_error, Imp_def))
# "[ISO] catch/3".
catch_test8(Y) :- catch(p_catch__coo8(_X), Y, true).
p_catch__coo8(X) :- throw(X).
% ---------------------------------------------------------------------------
%! ## 7.8.10 throw/1 ISOcore#p53
% (see 7.8.9 catch/3)
% ===========================================================================
%! # 8.2 Term unification
%! ## 8.2.1 (=)/2 ISOcore#p65
:- test unify_test1 + not_fails
# "[ISO] =/2".
unify_test1:- '='(1, 1).
:- test unify_test2(X) => (X=1)