From 0ad479498c48703ffdb218f3b70fab93e913bbe3 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Tue, 7 Nov 2023 10:28:36 +0100 Subject: [PATCH 1/4] Activate run_query() integration test --- src/machine/lib_machine.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/machine/lib_machine.rs b/src/machine/lib_machine.rs index 3a27b3d2..d7d183aa 100644 --- a/src/machine/lib_machine.rs +++ b/src/machine/lib_machine.rs @@ -422,9 +422,8 @@ mod tests { ); } - #[ignore = "fails on windows"] #[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 From 99055b553a70f4d5eb589a9e6a315e86ac1e1ab1 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 4 Dec 2023 20:10:06 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Don=E2=80=99t=20include=20unbound=20variabl?= =?UTF-8?q?es=20in=20results=20returned=20from=20run=5Fquery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/machine/lib_machine.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/machine/lib_machine.rs b/src/machine/lib_machine.rs index b0cc880f..9d166c51 100644 --- a/src/machine/lib_machine.rs +++ b/src/machine/lib_machine.rs @@ -196,7 +196,9 @@ 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 +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] fn list_results() { let mut machine = Machine::new_lib(); @@ -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"), } ),])) ); From 24e3e1794e773e87b7d735b61674ed1c1240661f Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Mon, 4 Dec 2023 20:18:41 +0100 Subject: [PATCH 3/4] cargo fmt --- src/machine/lib_machine.rs | 22 +++++++++++----------- src/machine/machine_errors.rs | 11 ++--------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/machine/lib_machine.rs b/src/machine/lib_machine.rs index 9d166c51..240f1777 100644 --- a/src/machine/lib_machine.rs +++ b/src/machine/lib_machine.rs @@ -197,8 +197,11 @@ impl Machine { // println!("Result: {} = {}", var_key.to_string(), output); if var_key.to_string() != output { - bindings.insert(var_key.to_string(), Value::try_from(output).expect("Couldn't convert Houtput to Value")); - } + bindings.insert( + var_key.to_string(), + Value::try_from(output).expect("Couldn't convert Houtput to Value"), + ); + } } matches.push(QueryResolutionLine::Match(bindings)); @@ -345,17 +348,14 @@ mod tests { let mut machine = Machine::new_lib(); machine.load_module_string( "facts", - r#" + r#" :- discontiguous(subject_class/2). - "#.to_string()); - - let result = machine.run_query(String::from( - "subject_class(X, _).", - )); - assert_eq!( - result, - Ok(QueryResolution::True) + "# + .to_string(), ); + + let result = machine.run_query(String::from("subject_class(X, _).")); + assert_eq!(result, Ok(QueryResolution::True)); } #[test] diff --git a/src/machine/machine_errors.rs b/src/machine/machine_errors.rs index 02133f32..49d56510 100644 --- a/src/machine/machine_errors.rs +++ b/src/machine/machine_errors.rs @@ -497,18 +497,11 @@ impl MachineState { let stub = functor!( atom!("module_does_not_contain_claimed_export"), - [ - atom(module_name), - str(self.heap.len() + 4, 0) - ], + [atom(module_name), str(self.heap.len() + 4, 0)], [functor_stub] ); - self.permission_error( - Permission::Access, - atom!("private_procedure"), - stub, - ) + self.permission_error(Permission::Access, atom!("private_procedure"), stub) } SessionError::ModuleCannotImportSelf(module_name) => { let error_atom = atom!("module_cannot_import_self"); From 77ce5a9586658e9ccdac1ad9af42c8bfdd0cc572 Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Tue, 5 Dec 2023 15:00:07 +0100 Subject: [PATCH 4/4] Result with one empty match should be false --- src/machine/lib_machine.rs | 2 +- src/machine/parsed_results.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/machine/lib_machine.rs b/src/machine/lib_machine.rs index 240f1777..23f8738c 100644 --- a/src/machine/lib_machine.rs +++ b/src/machine/lib_machine.rs @@ -355,7 +355,7 @@ mod tests { ); let result = machine.run_query(String::from("subject_class(X, _).")); - assert_eq!(result, Ok(QueryResolution::True)); + assert_eq!(result, Ok(QueryResolution::False)); } #[test] 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; } } }