Add test for programatic queries

This commit is contained in:
Nicolas Luck
2023-07-12 11:57:53 +02:00
parent f65675836c
commit c0dd94c8a3
5 changed files with 92 additions and 9 deletions

View File

@@ -936,3 +936,40 @@ impl Machine {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn programatic_query() {
let mut machine = Machine::with_test_streams();
machine.load_module_string("facts", String::from(r#"
triple("a", "p1", "b").
triple("a", "p2", "b").
"#));
let query = String::from(r#"triple("a",P,"b")."#);
let output = machine.run_query(query);
assert_eq!(output, QueryResult::Matches(vec![
QueryMatch::from(btreemap!{
"P" => Value::from("p1"),
}),
QueryMatch::from(btreemap!{
"P" => Value::from("p2"),
}),
]));
assert_eq!(
machine.run_query(String::from(r#"triple("a","p1","b")."#)),
QueryResult::True
);
assert_eq!(
machine.run_query(String::from(r#"triple("x","y","z")."#)),
QueryResult::False
);
}
}