]> Repositorios git - scryer-prolog.git/commitdiff
fmt
authorNicolas Luck <[email protected]>
Mon, 29 Jan 2024 17:44:20 +0000 (18:44 +0100)
committerNicolas Luck <[email protected]>
Mon, 29 Jan 2024 17:44:20 +0000 (18:44 +0100)
src/machine/lib_machine.rs
src/machine/parsed_results.rs

index cee7e6eb7bea6bedd42a87b1eb7cdfda231c83c2..2279d667a148cfcabda93d323dee04292911b8c5 100644 (file)
@@ -491,12 +491,8 @@ mod tests {
                 machine.consult_module_string("facts", code.to_string());
             } else if let Some(result) = block.strip_prefix("result") {
                 if let Some(Ok(ref last_result)) = last_result {
-                    assert_eq!(
-                        last_result.to_string().trim(),
-                        result.to_string().trim(),
-                    )
+                    assert_eq!(last_result.to_string().trim(), result.to_string().trim(),)
                 }
-                
             }
         }
     }
@@ -548,21 +544,13 @@ mod tests {
             ),
         );
 
-        let query =
-            String::from(r#"property_resolve(C, "isLiked"), subject_class("Todo", C)."#);
+        let query = String::from(r#"property_resolve(C, "isLiked"), subject_class("Todo", C)."#);
         let output = machine.run_query(query);
-        assert_eq!(
-            output,
-            Ok(QueryResolution::False)
-        );
+        assert_eq!(output, Ok(QueryResolution::False));
 
-        let query =
-        String::from(r#"subject_class("Todo", C), property_resolve(C, "isLiked")."#);
+        let query = String::from(r#"subject_class("Todo", C), property_resolve(C, "isLiked")."#);
         let output = machine.run_query(query);
-        assert_eq!(
-            output,
-            Ok(QueryResolution::False)
-        );
+        assert_eq!(output, Ok(QueryResolution::False));
     }
 
     #[test]
@@ -579,36 +567,20 @@ mod tests {
             ),
         );
 
-        let query =
-            String::from(r#"a("true for a")."#);
+        let query = String::from(r#"a("true for a")."#);
         let output = machine.run_query(query);
-        assert_eq!(
-            output,
-            Ok(QueryResolution::True)
-        );
+        assert_eq!(output, Ok(QueryResolution::True));
 
-        let query =
-            String::from(r#"a("true for a"), b("true for b")."#);
+        let query = String::from(r#"a("true for a"), b("true for b")."#);
         let output = machine.run_query(query);
-        assert_eq!(
-            output,
-            Ok(QueryResolution::True)
-        );
+        assert_eq!(output, Ok(QueryResolution::True));
 
-        let query =
-            String::from(r#"a("true for b"), b("true for b")."#);
+        let query = String::from(r#"a("true for b"), b("true for b")."#);
         let output = machine.run_query(query);
-        assert_eq!(
-            output,
-            Ok(QueryResolution::False)
-        );
+        assert_eq!(output, Ok(QueryResolution::False));
 
-        let query =
-            String::from(r#"a("true for a"), b("true for a")."#);
+        let query = String::from(r#"a("true for a"), b("true for a")."#);
         let output = machine.run_query(query);
-        assert_eq!(
-            output,
-            Ok(QueryResolution::False)
-        );
+        assert_eq!(output, Ok(QueryResolution::False));
     }
 }
index 56b1750f1fa7d0a4e5cd0f59d18f206b3a2cf44f..738bc9385e408bf2ce2f7e551f3d023aab149ad5 100644 (file)
@@ -19,19 +19,22 @@ pub fn prolog_value_to_json_tring(value: Value) -> String {
         Value::Float(f) => format!("{}", f),
         Value::Rational(r) => format!("{}", r),
         Value::Atom(a) => format!("{}", a.as_str()),
-        Value::String(s) => 
+        Value::String(s) => {
             if let Err(_e) = serde_json::from_str::<serde_json::Value>(s.as_str()) {
                 //treat as string literal
                 //escape double quotes
-                format!("\"{}\"", s
-                    .replace("\"", "\\\"")
-                    .replace("\n", "\\n")
-                    .replace("\t", "\\t")
-                    .replace("\r", "\\r"))
+                format!(
+                    "\"{}\"",
+                    s.replace("\"", "\\\"")
+                        .replace("\n", "\\n")
+                        .replace("\t", "\\t")
+                        .replace("\r", "\\r")
+                )
             } else {
                 //return valid json string
                 s
-            },
+            }
+        }
         Value::List(l) => {
             let mut string_result = "[".to_string();
             for (i, v) in l.iter().enumerate() {
@@ -64,7 +67,11 @@ fn prolog_match_to_json_string(query_match: &QueryMatch) -> String {
         if i > 0 {
             string_result.push_str(",");
         }
-        string_result.push_str(&format!("\"{}\":{}", k, prolog_value_to_json_tring(v.clone())));
+        string_result.push_str(&format!(
+            "\"{}\":{}",
+            k,
+            prolog_value_to_json_tring(v.clone())
+        ));
     }
     string_result.push_str("}");
     string_result