summary refs log tree commit diff stats
path: root/tests/basic_match.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/basic_match.rs')
-rw-r--r--tests/basic_match.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/tests/basic_match.rs b/tests/basic_match.rs
index a1c62bb..b58457e 100644
--- a/tests/basic_match.rs
+++ b/tests/basic_match.rs
@@ -16,14 +16,47 @@ fn test_basic() {
         yk: String,
         y: usize,
     }
-    // should this error about needing multiple results/Vec requirement?
-    let matches: Values = pat.deserialize(&mut der).unwrap();
+    let matches: Values = pat.deserialize(&mut der).unwrap().collect().unwrap();
     assert_eq!(matches.x, "bar");
     assert_eq!(matches.yk, "baz");
     assert_eq!(matches.y, 2);
     assert!(der.end().is_ok());
 }
 
+#[test]
+fn test_real_use_case() {
+    let pat = datafu::PatternBuilder::for_pattern(
+        "
+        :map
+        ->['projects'?]:map
+          ->[commit:?str]:?map
+            ->[url:?str]:?map
+              ->[branch:?str]:?map
+                (->['active'?]active:?bool)?
+                (->['federate'?]?federate:?bool)?
+                (->['pinned'?]?pinned:?bool)?
+        "
+    ).compile().unwrap();
+    let data = r#"
+    {"base_url": "https://ganarchy.autistic.space", "repo_list_srcs": {"https://ganarchy.autistic.space/index.toml": {"active": false}}, "projects": {"385e734a52e13949a7a5c71827f6de920dbfea43": {"https://github.com/ganarchy/GAnarchy": {"HEAD": {"active": true}}, "https://soniex2.autistic.space/git-repos/ganarchy.git": {"HEAD": {"active": true, "pinned": true}}}, "a8fb5087f79eafe312db270082c052c427b208c2": {"https://soniex2.autistic.space/git-repos/mmorfc.git": {"HEAD": {"active": true, "pinned": true}}}, "2d0b363fe3179087de59d9ef4a2d14af21d89071": {"https://soniex2.autistic.space/git-repos/chewstuff.git": {"HEAD": {"active": true, "pinned": true}}}}}
+    "#;
+    let mut der = JsonDer::from_str(data);
+    #[derive(Deserialize)]
+    struct Values {
+        commit: String,
+        url: String,
+        branch: String,
+        active: bool,
+        #[serde(default)]
+        federate: bool,
+        #[serde(default)]
+        pinned: bool,
+    }
+    let graph = pat.deserialize(&mut der).unwrap();
+    let matches: Vec<Values> = graph.collect().unwrap();
+    assert!(der.end().is_ok());
+}
+
 //#[test]
 //fn test_str() {
 //    //let tree = Value::M(vec![