diff --git a/src/machine/lib_machine.rs b/src/machine/lib_machine.rs index 54f9ba95..23f8738c 100644 --- a/src/machine/lib_machine.rs +++ b/src/machine/lib_machine.rs @@ -196,7 +196,12 @@ impl Machine { let output: String = outputter.result(); // 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)); @@ -338,6 +343,21 @@ 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::False)); + } + #[test] fn list_results() { let mut machine = Machine::new_lib(); @@ -425,7 +445,7 @@ mod tests { } #[test] - fn stress_integration_test() { + fn integration_test() { let mut machine = Machine::new_lib(); // File with test commands, i.e. program code to consult and queries to run @@ -486,14 +506,12 @@ mod tests { output, Ok(QueryResolution::Matches(vec![QueryMatch::from( btreemap! { - "Predicate" => Value::from("Predicate"), "Result" => Value::List( Vec::from([ Value::List([Value::from("p1"), Value::from("b")].into()), Value::List([Value::from("p2"), Value::from("b")].into()), ]) ), - "Target" => Value::from("Target"), } ),])) ); diff --git a/src/machine/parsed_results.rs b/src/machine/parsed_results.rs index 24dccc5e..bbc9b091 100644 --- a/src/machine/parsed_results.rs +++ b/src/machine/parsed_results.rs @@ -65,11 +65,11 @@ impl From> for QueryResolution { } } - // If there is only one line, and it is an empty match, return true. + // If there is only one line, and it is an empty match, return false. if query_result_lines.len() == 1 { if let QueryResolutionLine::Match(m) = query_result_lines[0].clone() { if m.is_empty() { - return QueryResolution::True; + return QueryResolution::False; } } }