fix bug in DeleteAttribute

This commit is contained in:
Mark Thom
2019-02-02 19:25:12 -07:00
parent a28c8934f3
commit f51405bc04
5 changed files with 90 additions and 37 deletions

View File

@@ -2133,3 +2133,54 @@ fn test_queries_on_string_lists()
assert_prolog_success!(&mut wam, "?- partial_string(\"abc\", X), partial_string(\"abcdef\", X), X = \"abcdef\".",
[["X = [a, b, c, d, e, f]"]]);
}
#[test]
fn test_queries_on_attributed_variables()
{
let mut wam = Machine::new();
submit(&mut wam, "
:- module(my_mod, []).
:- use_module(library(atts)).
:- attribute dif/1, frozen/1.");
assert_prolog_success!(&mut wam, "?- ( put_atts(V, my_mod, dif(1)) ; put_atts(V, my_mod, dif(2)) ),
get_atts(V, my_mod, L).",
[["L = [dif(1) | _17]", "V = _12"],
["L = [dif(2) | _17]", "V = _12"]]);
assert_prolog_success!(&mut wam, "?- put_atts(V, my_mod, frozen(a)),
( put_atts(V, my_mod, dif(1))
; put_atts(V, my_mod, -frozen(a)), put_atts(V, my_mod, dif(2))
; put_atts(V, my_mod, dif(different)) ),
get_atts(V, my_mod, Ls).",
[["Ls = [frozen(a), dif(1) | _37]", "V = _12"],
["Ls = [dif(2) | _51]", "V = _12"],
["Ls = [frozen(a), dif(different) | _37]", "V = _12"]]);
assert_prolog_success!(&mut wam, "?- put_atts(V, my_mod, [dif(1), dif(2), frozen(a)]),
( put_atts(V, my_mod, -dif(2)) ; put_atts(V, my_mod, -frozen(A)) ),
get_atts(V, my_mod, L).",
[["A = _70", "L = [dif(1), frozen(a) | _68]", "V = _27"],
["A = _70", "L = [dif(1), dif(2) | _68]", "V = _27"]]);
assert_prolog_success!(&mut wam, "?- put_atts(V, my_mod, [dif(1), dif(2), frozen(a), frozen(b)]),
( put_atts(V, my_mod, -dif(2)) ; put_atts(V, my_mod, -frozen(A)) ),
get_atts(V, my_mod, L).",
[["A = _98", "L = [dif(1), frozen(a), frozen(b) | _96]", "V = _31"],
["A = _98", "L = [dif(1), dif(2) | _96]", "V = _31"]]);
assert_prolog_failure!(&mut wam, "?- put_atts(V, my_mod, [dif(1), dif(2), frozen(a), frozen(b)]),
get_atts(V, my_mod, -dif(1)).");
assert_prolog_success!(&mut wam, "?- put_atts(V, my_mod, [dif(1), dif(2), frozen(a), frozen(b)]),
get_atts(V, my_mod, -dif(3)).");
assert_prolog_success!(&mut wam, "?- put_atts(V, my_mod, [dif(1), dif(2), frozen(a), frozen(b)]),
get_atts(V, my_mod, dif(X)).",
[["X = 1", "V = _31"],
["X = 2", "V = _31"]]);
assert_prolog_success!(&mut wam, "?- put_atts(V, my_mod, [dif(1), dif(2), frozen(a), frozen(b)]),
put_atts(V, my_mod, -dif(A)), get_atts(V, my_mod, Ls).",
[["A = _99", "Ls = [frozen(a), frozen(b) | _96]", "V = _31"]]);
assert_prolog_success!(&mut wam, "?- put_atts(V, my_mod, [dif(1), frozen(a), dif(2), frozen(b)]),
put_atts(V, my_mod, -dif(A)), get_atts(V, my_mod, Ls).",
[["A = _99", "Ls = [frozen(a), frozen(b) | _96]", "V = _31"]]);
}