Don’t include unbound variables in results returned from run_query
This commit is contained in:
@@ -196,7 +196,9 @@ impl Machine {
|
|||||||
let output: String = outputter.result();
|
let output: String = outputter.result();
|
||||||
// println!("Result: {} = {}", var_key.to_string(), output);
|
// println!("Result: {} = {}", var_key.to_string(), output);
|
||||||
|
|
||||||
bindings.insert(var_key.to_string(), Value::try_from(output).expect("asdfs"));
|
if var_key.to_string() != output {
|
||||||
|
bindings.insert(var_key.to_string(), Value::try_from(output).expect("Couldn't convert Houtput to Value"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
matches.push(QueryResolutionLine::Match(bindings));
|
matches.push(QueryResolutionLine::Match(bindings));
|
||||||
@@ -338,6 +340,24 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_predicate() {
|
||||||
|
let mut machine = Machine::new_lib();
|
||||||
|
machine.load_module_string(
|
||||||
|
"facts",
|
||||||
|
r#"
|
||||||
|
:- discontiguous(subject_class/2).
|
||||||
|
"#.to_string());
|
||||||
|
|
||||||
|
let result = machine.run_query(String::from(
|
||||||
|
"subject_class(X, _).",
|
||||||
|
));
|
||||||
|
assert_eq!(
|
||||||
|
result,
|
||||||
|
Ok(QueryResolution::True)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_results() {
|
fn list_results() {
|
||||||
let mut machine = Machine::new_lib();
|
let mut machine = Machine::new_lib();
|
||||||
@@ -486,14 +506,12 @@ mod tests {
|
|||||||
output,
|
output,
|
||||||
Ok(QueryResolution::Matches(vec![QueryMatch::from(
|
Ok(QueryResolution::Matches(vec![QueryMatch::from(
|
||||||
btreemap! {
|
btreemap! {
|
||||||
"Predicate" => Value::from("Predicate"),
|
|
||||||
"Result" => Value::List(
|
"Result" => Value::List(
|
||||||
Vec::from([
|
Vec::from([
|
||||||
Value::List([Value::from("p1"), Value::from("b")].into()),
|
Value::List([Value::from("p1"), Value::from("b")].into()),
|
||||||
Value::List([Value::from("p2"), Value::from("b")].into()),
|
Value::List([Value::from("p2"), Value::from("b")].into()),
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
"Target" => Value::from("Target"),
|
|
||||||
}
|
}
|
||||||
),]))
|
),]))
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user