From: Mark Thom Date: Mon, 8 Oct 2018 06:51:11 +0000 (-0600) Subject: add DCG test case X-Git-Tag: v0.8.110~340 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=1dc015b91fcbc767819f52fe90d6997add74256c;p=scryer-prolog.git add DCG test case --- 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() {