add tests for string lists, structural equality on string lists.
This commit is contained in:
@@ -31,8 +31,10 @@ Extend rusty-wam to include the following, among other features:
|
|||||||
control (`setup_call_control/3`, `call_with_inference_limit/3`,
|
control (`setup_call_control/3`, `call_with_inference_limit/3`,
|
||||||
etc.) (_done_)
|
etc.) (_done_)
|
||||||
* Default representation of strings as list of chars, using a packed
|
* Default representation of strings as list of chars, using a packed
|
||||||
internal representation (_in progress_).
|
internal representation (_done_).
|
||||||
* `term_expansion/2` and `goal_expansion/2`.
|
** Implement a representation of 'partial strings' as difference lists
|
||||||
|
of characters (_in progress_).
|
||||||
|
* `term_expansion/2` and `goal_expansion/2` (_in progress_).
|
||||||
* Definite Clause Grammars.
|
* Definite Clause Grammars.
|
||||||
* Attributed variables using the SICStus Prolog interface and
|
* Attributed variables using the SICStus Prolog interface and
|
||||||
semantics. Adding coroutines like `dif/2`, `freeze/2`, etc.
|
semantics. Adding coroutines like `dif/2`, `freeze/2`, etc.
|
||||||
|
|||||||
@@ -1785,10 +1785,33 @@ impl MachineState {
|
|||||||
|
|
||||||
for (v1, v2) in iter {
|
for (v1, v2) in iter {
|
||||||
match (v1, v2) {
|
match (v1, v2) {
|
||||||
(HeapCellValue::Addr(Addr::Lis(_)), HeapCellValue::Addr(Addr::Con(Constant::String(ref s))))
|
(HeapCellValue::Addr(Addr::Lis(l)), HeapCellValue::Addr(Addr::Con(Constant::String(ref s))))
|
||||||
| (HeapCellValue::Addr(Addr::Con(Constant::String(ref s))), HeapCellValue::Addr(Addr::Lis(_)))
|
| (HeapCellValue::Addr(Addr::Con(Constant::String(ref s))), HeapCellValue::Addr(Addr::Lis(l)))
|
||||||
if self.flags.double_quotes.is_chars() => if s.is_empty() {
|
if self.flags.double_quotes.is_chars() => if s.is_empty() {
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
if let HeapCellValue::Addr(Addr::Con(constant)) = self.heap[l].clone() {
|
||||||
|
if let Some(c) = s.head() {
|
||||||
|
// checks equality on atoms, too.
|
||||||
|
if constant == Constant::Char(c) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
(HeapCellValue::Addr(Addr::Con(Constant::String(ref s1))),
|
||||||
|
HeapCellValue::Addr(Addr::Con(Constant::String(ref s2)))) =>
|
||||||
|
match s1.head() {
|
||||||
|
Some(c1) => if let Some(c2) = s2.head() {
|
||||||
|
if c1 != c2 {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
None => return !s2.is_empty()
|
||||||
},
|
},
|
||||||
(HeapCellValue::Addr(Addr::Con(Constant::String(ref s))),
|
(HeapCellValue::Addr(Addr::Con(Constant::String(ref s))),
|
||||||
HeapCellValue::Addr(Addr::Con(Constant::EmptyList)))
|
HeapCellValue::Addr(Addr::Con(Constant::EmptyList)))
|
||||||
|
|||||||
53
src/tests.rs
53
src/tests.rs
@@ -1734,5 +1734,56 @@ fn test_queries_on_call_with_inference_limit()
|
|||||||
[["R = !", "X = 6"]]);
|
[["R = !", "X = 6"]]);
|
||||||
assert_prolog_success!(&mut wam, "?- call_with_inference_limit(g(X), 1, R), call_with_inference_limit(g(X), 1, R).",
|
assert_prolog_success!(&mut wam, "?- call_with_inference_limit(g(X), 1, R), call_with_inference_limit(g(X), 1, R).",
|
||||||
[["R = inference_limit_exceeded", "X = _1"]]);
|
[["R = inference_limit_exceeded", "X = _1"]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_queries_on_string_lists()
|
||||||
|
{
|
||||||
|
let mut wam = Machine::new();
|
||||||
|
|
||||||
|
// double_quotes is chars by default.
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"\" == [].");
|
||||||
|
assert_prolog_failure!(&mut wam, "?- \"abc\" == [].");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"abc\" == ['a', 'b', 'c'].");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"abc\" == ['a', 'b', c].");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"abc\" == ['a', b, 'c'].");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"abc\" == [a, 'b', 'c'].");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"abc\" == [a, 'b', c].");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"koen\" == [k, o, e, n].");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"koen\" = [k, o, e, n].");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"koen\" =@= [k, o, e, n].");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"koen\" =@= \"koen\".");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"koen\" = [k, o | X].",
|
||||||
|
[["X = [e, n]"]]);
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"koen\" = [k, o | X], X = \"en\".",
|
||||||
|
[["X = [e, n]"]]);
|
||||||
|
assert_prolog_failure!(&mut wam, "?- \"koen\" = [k, o | X], X == \"en\".");
|
||||||
|
assert_prolog_success!(&mut wam, "?- \"koen\" = [k, o | X], X =@= \"en\".",
|
||||||
|
[["X = [e, n]"]]);
|
||||||
|
|
||||||
|
submit(&mut wam, "matcher([a,b,c|X], ['d','e','f'|X]).");
|
||||||
|
|
||||||
|
assert_prolog_success!(&mut wam, "?- matcher(\"abcdef\", \"defdef\").");
|
||||||
|
assert_prolog_failure!(&mut wam, "?- matcher(\"abcdef\", \"defdff\").");
|
||||||
|
|
||||||
|
assert_prolog_success!(&mut wam, "?- matcher([X, Y, Z | W], [A, B, C | W]).",
|
||||||
|
[["A = d", "B = e", "C = f", "W = _1", "X = a", "Y = b", "Z = c"]]);
|
||||||
|
assert_prolog_failure!(&mut wam, "?- matcher([X, Y, Z | W], [X, B, C | W]).");
|
||||||
|
|
||||||
|
submit(&mut wam, "matcher([a,b,c|X], X).");
|
||||||
|
|
||||||
|
assert_prolog_success!(&mut wam, "?- matcher(\"abcdef\", X), X = [d,e,f|Y], Y == [], X = \"def\".",
|
||||||
|
[["X = [d, e, f]", "Y = []"]]);
|
||||||
|
assert_prolog_failure!(&mut wam, "?- matcher(\"abcdef\", X), X = [d,e,f|Y], Y == [], X == \"def\".");
|
||||||
|
assert_prolog_success!(&mut wam, "?- X = ['a', 'b', 'c' | \"def\"].",
|
||||||
|
[["X = [a, b, c, d, e, f]"]]);
|
||||||
|
|
||||||
|
assert_prolog_success!(&mut wam, "?- X = [a,b,c|\"abc\"].",
|
||||||
|
[["X = [a, b, c, a, b, c]"]]);
|
||||||
|
|
||||||
|
submit(&mut wam, "?- set_prolog_flag(double_quotes, atom).");
|
||||||
|
|
||||||
|
assert_prolog_success!(&mut wam, "?- matcher(X, Y).",
|
||||||
|
[["X = [a, b, c | _1]", "Y = _1"]]);
|
||||||
|
assert_prolog_failure!(&mut wam, "?- matcher(\"abcdef\", Y).");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user