From: Mark Thom Date: Tue, 19 Nov 2019 06:17:56 +0000 (-0700) Subject: add setup_call_cleanup tests, expand builtins tests X-Git-Tag: v0.8.118~38^2~18 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=66bebff01eb14c5a8273fec3875aa535731d44e5;p=scryer-prolog.git add setup_call_cleanup tests, expand builtins tests --- diff --git a/src/tests/builtins.pl b/src/tests/builtins.pl index 47d1e509..4b614023 100644 --- a/src/tests/builtins.pl +++ b/src/tests/builtins.pl @@ -1,5 +1,6 @@ :- use_module(library(lists)). +:- use_module(library(non_iso)). test_queries_on_builtins :- \+ atom(_), @@ -20,7 +21,7 @@ test_queries_on_builtins :- atomic(0.0), \+ atomic([a,b,c]), \+ atomic(atop(the_trees)), - ( var(X), X = 3, atomic(X) ), + findall(X, ( var(X), X = 3, atomic(X) ), [3]), \+ ( var(X), X = 3, var(X) ), arg(1, f(a,b,c,d), a), arg(2, f(a,b,c,d), b), @@ -36,7 +37,6 @@ test_queries_on_builtins :- length([a,b,c], 3), copy_term([[[[X,Y],Y],X]],[[[[Z,V],V],Z]]), \+ ( X = g(X,Y), Y = f(X), copy_term(Y,g(Z)) ), - (X = g(X,Y), Y = f(X), copy_term(Y,f(Z))), float(3.14159269), \+ float(3), \+ float("sdfsa"), @@ -44,7 +44,7 @@ test_queries_on_builtins :- \+ float([1,2,3]), \+ float([1,2,_]), \+ (X is 3 rdiv 4, float(X)), - ( X is 3 rdiv 4, rational(X) ), + \+ \+ (X is 3 rdiv 4, rational(X)), \+ rational(3), \+ rational(f(_)), \+ rational("sdfa"), @@ -59,6 +59,71 @@ test_queries_on_builtins :- \+ compound(3.14159269), \+ compound(3), \+ compound("sdfsa"), - \+ compound(atom). + \+ compound(atom), + \+ string(functor(string)), + \+ string(3.14159269), + \+ string(3), + \+ string(f(X)), + string("sdfsa"), + \+ string(atom), + \+ string([1,2,3]), + \+ string([1,2,X]), + \+ \+ ( X = nonvar, nonvar(X) ), + \+ nonvar(X), + \+ \+ nonvar(f(X)), + nonvar(functor(nonvar)), + nonvar(3.14159269), + nonvar(3), + nonvar("sdfsa"), + nonvar(atom), + nonvar([1,2,3]), + \+ \+ nonvar([1,2,X]), + \+ \+ (A = f(A), ground(f(f(A))),ground(f(A)),ground(A)), + \+ (B = f(A),ground(B)), + \+ (B = f(A),ground(A)), + \+ \+ ( ground(x),ground(f(x)),X = f(x),ground(g(f(X),[a,b])) ), + \+ \+ (A = f(A),g(A,B) == g(f(A),B)), + \+ (A = f(A),g(A,B) == g(f(A),b)), + \+ (A == B), + \+ (A == 12.1), + \+ \+ (X = x,f(X,x) == f(x,X)), + \+ (A = f(A),g(A,B) \== g(f(A),B)), + \+ \+ (A = f(A),g(A,B) \== g(f(A),b)), + \+ \+ (A \== B), + \+ \+ (A \== 12.1), + \+ (X = x,f(X,x) \== f(x,X)), + \+ \+ (X @=< Y), + \+ (X @>= Y), + \+ (X @> Y), + \+ \+ (X @>= X), + \+ (atom @=< "string"), + \+ \+ (atom @=< atom), + \+ (atom @=< aaa), + \+ \+ (atom @>= "string"), + \+ \+ (X is 3 + 3,X @>= Y), + \+ \+ (f(X) @>= f(X)), + \+ \+ (f(X) @>= a), + \+ (f(X) @=< a), + [1,2] @=< [1,2], + \+ ([1,2,3] @=< [1,2]), + \+ \+ ([] @=< [1,2]), + \+ ([] @< 1), + \+ ([] @< "string"), + \+ ([] @< atom), + atom @< [], + 1.1 @< 1, + 1.0 @=< 1, + 1 @=< 1.0, + \+ \+ (variant(X, Y)), + \+ (variant(f(X), f(x))), + \+ \+ (variant(X, X)), + \+ \+ (variant(f(x), f(x))), + \+ (variant([X,Y,Z], [V,W,V])), + \+ \+ (variant([X,Y,Z], [V,W,Z])), + \+ \+ (variant([X,Y,X], [V,W,V])), + \+ \+ (g(B) = B, g(A) = A, variant(A, B)), + keysort([1-1,1-1],[1-1,1-1]), + findall(Sorted, keysort([2-99,1-a,3-f(_),1-z,1-a,2-44],Sorted), [[1-a,1-z,1-a,2-99,2-44,3-f(_)]]), + findall(X, keysort([X-1,1-1],[2-1,1-1]), [2]). :- initialization(test_queries_on_builtins). diff --git a/src/tests/setup_call_cleanup.pl b/src/tests/setup_call_cleanup.pl new file mode 100644 index 00000000..b3c6a9bb --- /dev/null +++ b/src/tests/setup_call_cleanup.pl @@ -0,0 +1,27 @@ + +:- use_module(library(non_iso)). + +test_queries_on_setup_call_cleanup :- + \+ setup_call_cleanup(false, _, _), + catch(setup_call_cleanup(true, throw(unthrown), _), error(instantiation_error, _), true), + setup_call_cleanup(true, true, (true ; throw(x))), + findall(X, setup_call_cleanup(true, X = 1, X = 2), [1]), + findall(X, setup_call_cleanup(true, true, X = 2), [2]), + findall(E, catch(setup_call_cleanup(true, X=true, X), error(E, _), true), [instantiation_error]), + catch(setup_call_cleanup(X=throw(ex), true, X), ex, true), + findall([S,G,C], setup_call_cleanup(S = 1, G = 2, C = 3), [[1,2,3]]), + findall([S,G,C], setup_call_cleanup((S=1;S=2), G=3, C=4), [[1,3,4]]), + findall([S,G], setup_call_cleanup(S=1, G=2, writeq(S+G)), [[1,2]]), + findall([S,G], setup_call_cleanup(S=1, (G=2;G=3), writeq(S+G)), [[1,2],[1,3]]), + findall([S,G], (setup_call_cleanup(S=1, G=2, writeq(S+G>A+B)), A = 3, B = 4), [[1,2]]), + findall([S,G,E], catch(setup_call_cleanup(S=1, (G=2;G=3,throw(x)), writeq(S+G)), E, true), [[1,2,_],[_,_,x]]), + findall([S,B,G], (setup_call_cleanup(S=1, (G=2;G=3),writeq(S+G>B)), B=4, !), [[1,4,2]]), + findall([S,G,B], (setup_call_cleanup(S=1,G=2,writeq(S+G>B)),B=3,!), [[1,2,3]]), + findall([S,G,B], (setup_call_cleanup(S=1,(G=2;false),writeq(S+G>B)),B=3,!), [[1,2,3]]), + findall([S,G,B], (setup_call_cleanup(S=1,(G=2;S=2),writeq(S+G>B)), B=3, !), [[1,2,3]]), + catch((setup_call_cleanup(S=1,(G=2;G=3), writeq(S+G>B)), B=4, !, throw(x)), x, true), + findall(Pat, catch(setup_call_cleanup(true,throw(goal),throw(cl)), Pat, true), [goal]), + findall(Pat, catch(( setup_call_cleanup(true,(G=1;G=2),throw(cl)), throw(cont)), Pat, true), [cont]), + findall([X,Y], (setup_call_cleanup(true, (X=1;X=2), writeq(a)), setup_call_cleanup(true,(Y=1;Y=2),writeq(b)), !), [[1,1]]). + +:- initialization(test_queries_on_setup_call_cleanup).