From 5c5257bdbdeaf0dbeb236911f3d2ec23038d5b44 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Thu, 22 Feb 2018 18:33:00 -0700 Subject: [PATCH] add more tests --- src/prolog/machine/machine_state.rs | 2 +- src/tests.rs | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/prolog/machine/machine_state.rs b/src/prolog/machine/machine_state.rs index 94daa4ac..b9663d6c 100644 --- a/src/prolog/machine/machine_state.rs +++ b/src/prolog/machine/machine_state.rs @@ -370,7 +370,7 @@ impl CallWithInferenceLimitCallPolicy { *policy = Box::new(new_policy); } - fn increment(&mut self) -> CallResult { + fn increment(&mut self) -> CallResult { if let Some(&(ref limit, bp)) = self.limits.last() { if self.count == **limit { return Err(functor!(self.atom_tbl, diff --git a/src/tests.rs b/src/tests.rs index ed576758..e7868ae9 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1326,7 +1326,7 @@ fn test_queries_on_builtins() assert_prolog_failure!(&mut wam, "?- string(atom)."); assert_prolog_failure!(&mut wam, "?- string([1,2,3])."); assert_prolog_failure!(&mut wam, "?- string([1,2,X])."); - + assert_prolog_success!(&mut wam, "?- X = nonvar, nonvar(X)."); assert_prolog_failure!(&mut wam, "?- nonvar(X)."); assert_prolog_success!(&mut wam, "?- nonvar(f(X))."); @@ -1441,15 +1441,14 @@ fn test_queries_on_setup_call_cleanup() assert_prolog_success!(&mut wam, "?- catch(setup_call_cleanup(true,throw(goal),throw(cl)), Pat, true).", [["Pat = goal"]]); assert_prolog_success!(&mut wam, "?- catch(( setup_call_cleanup(true,(G=1;G=2),throw(cl)), throw(cont)), Pat, true).", - [["Pat = cont", "G = _1"]]); + [["Pat = cont", "G = _1"]]); } #[test] fn test_queries_on_call_with_inference_limit() -{ +{ let mut wam = Machine::new(); - // inference_limit_exceeded thrown on 0 limit. assert_prolog_success!(&mut wam, "?- call_with_inference_limit(throw(error), 0, R).", [["R = inference_limit_exceeded"]]); assert_prolog_success!(&mut wam, "?- catch(call_with_inference_limit(throw(error), 1, R), @@ -1457,7 +1456,7 @@ fn test_queries_on_call_with_inference_limit() true)."); assert_prolog_failure!(&mut wam, "?- call_with_inference_limit(g(X), 5, R)."); - + submit(&mut wam, "g(1). g(2). g(3). g(4). g(5)."); assert_prolog_success!(&mut wam, "?- call_with_inference_limit(g(X), 5, R).", @@ -1466,6 +1465,12 @@ fn test_queries_on_call_with_inference_limit() ["R = true", "X = 3"], ["R = true", "X = 4"], ["R = !", "X = 5"]]); + assert_prolog_success!(&mut wam, "?- call_with_inference_limit(g(X), 5, R), call(true).", + [["R = true", "X = 1"], + ["R = true", "X = 2"], + ["R = true", "X = 3"], + ["R = true", "X = 4"], + ["R = !", "X = 5"]]); assert_prolog_success!(&mut wam, "?- call_with_inference_limit(g(X), 2, R).", [["R = true", "X = 1"], ["R = true", "X = 2"], @@ -1496,7 +1501,7 @@ fn test_queries_on_call_with_inference_limit() [["R = inference_limit_exceeded", "X = _1"]]); submit(&mut wam, "e(X) :- call_with_inference_limit(f(X), 10, _)."); - + assert_prolog_success!(&mut wam, "?- call_with_inference_limit(e(X), 7, R).", [["R = true", "X = 1"], ["R = true", "X = 2"], @@ -1520,11 +1525,11 @@ fn test_queries_on_call_with_inference_limit() [["R = inference_limit_exceeded", "X = _1"]]); submit(&mut wam, "f(X, R) :- call_with_inference_limit(g(X), 5, R)."); - + assert_prolog_success!(&mut wam, "?- call_with_inference_limit(f(X, R), 3, S).", [["S = true", "X = 1", "R = true"], ["S = true", "X = 2", "R = true"], - ["S = inference_limit_exceeded", "X = _1", "R = _2"]]); + ["S = inference_limit_exceeded", "X = _1", "R = _2"]]); assert_prolog_success!(&mut wam, "?- call_with_inference_limit(f(X, R), 7, R).", [["R = true", "X = 1"], ["R = true", "X = 2"], -- 2.54.0