From 1dc015b91fcbc767819f52fe90d6997add74256c Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Mon, 8 Oct 2018 00:51:11 -0600 Subject: [PATCH] add DCG test case --- src/tests.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/tests.rs b/src/tests.rs index 16a31b06..c6e182c9 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1864,6 +1864,37 @@ fn test_queries_on_call_with_inference_limit() [["R = inference_limit_exceeded", "X = _1"]]); } +#[test] +fn test_queries_on_dcgs() +{ + let mut wam = Machine::new(); + + submit(&mut wam, ":- use_module(library(dcgs))."); + + // test case by YeGoblynQueene on hacker news. + compile_user_module(&mut wam, + " ability(destroy, X) --> destroy(X). + destroy(X) --> [destroy], target(X). + target(X) --> [target], permanent(X). + permanent(X) --> [creature], creature(X). + permanent(X) --> [artifact], artifact(X). + permanent(X) --> [land], land(X). + spell(X) --> [sorcery], sorcery(X). + spell(X) --> [instant], instant(X). + + creature('Llanowar Elves') --> []. + artifact('Ankh of Mishra') --> []. + land('Mountain') --> []. + % etc permanents + sorcery('Duress') --> []. + instant('Lightning Bolt') --> [].".as_bytes()); + + assert_prolog_success!(&mut wam, "?- phrase(ability(destroy, X), P).", + [["P = [destroy, target, creature | _4]", "X = 'Llanowar Elves'"], + ["P = [destroy, target, artifact | _4]", "X = 'Ankh of Mishra'"], + ["P = [destroy, target, land | _4]", "X = 'Mountain'"]]); +} + #[test] fn test_queries_on_string_lists() { -- 2.54.0