]> Repositorios git - scryer-prolog.git/commitdiff
add DCG test case
authorMark Thom <[email protected]>
Mon, 8 Oct 2018 06:51:11 +0000 (00:51 -0600)
committerMark Thom <[email protected]>
Mon, 8 Oct 2018 06:51:11 +0000 (00:51 -0600)
src/tests.rs

index 16a31b06027d369e6933ae7d640140f8be805174..c6e182c9dba5154d01e4de66a23dee52899c8101 100644 (file)
@@ -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()
 {