From d849f5e301fa47cfd87df1e7f1ad0346ddf387f1 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sat, 8 Apr 2023 18:52:00 -0300 Subject: Initial success --- tests/basic_match.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'tests') 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 = graph.collect().unwrap(); + assert!(der.end().is_ok()); +} + //#[test] //fn test_str() { // //let tree = Value::M(vec![ -- cgit 1.4.1