diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic_match.rs | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/tests/basic_match.rs b/tests/basic_match.rs index b58457e..632a1fe 100644 --- a/tests/basic_match.rs +++ b/tests/basic_match.rs @@ -6,22 +6,22 @@ use serde::Deserialize; //use datafu::Predicate; -#[test] -fn test_basic() { - let mut der = JsonDer::from_str(r#"{"foo": 1, "bar": {"baz": 2}}"#); - let pat = datafu::PatternBuilder::for_pattern("->[x]:?map->[yk]y").compile().unwrap(); - #[derive(Deserialize)] - struct Values { - x: String, - yk: String, - y: usize, - } - 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_basic() { +// let mut der = JsonDer::from_str(r#"{"foo": 1, "bar": {"baz": 2}}"#); +// let pat = datafu::PatternBuilder::for_pattern("->[x]:?map->[yk]y").compile().unwrap(); +// #[derive(Deserialize)] +// struct Values { +// x: String, +// yk: String, +// y: usize, +// } +// 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() { @@ -41,13 +41,14 @@ fn test_real_use_case() { {"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)] + fn always_true() -> bool { true } + #[derive(Deserialize, PartialEq, Eq, Debug)] struct Values { commit: String, url: String, branch: String, active: bool, - #[serde(default)] + #[serde(default="always_true")] federate: bool, #[serde(default)] pinned: bool, @@ -55,6 +56,41 @@ fn test_real_use_case() { let graph = pat.deserialize(&mut der).unwrap(); let matches: Vec<Values> = graph.collect().unwrap(); assert!(der.end().is_ok()); + assert_eq!(matches.len(), 4); + assert_eq!(&*matches, &[ + Values { + commit: "385e734a52e13949a7a5c71827f6de920dbfea43".into(), + url: "https://github.com/ganarchy/GAnarchy".into(), + branch: "HEAD".into(), + active: true, + federate: true, + pinned: false, + }, + Values { + commit: "385e734a52e13949a7a5c71827f6de920dbfea43".into(), + url: "https://soniex2.autistic.space/git-repos/ganarchy.git".into(), + branch: "HEAD".into(), + active: true, + federate: true, + pinned: true, + }, + Values { + commit: "a8fb5087f79eafe312db270082c052c427b208c2".into(), + url: "https://soniex2.autistic.space/git-repos/mmorfc.git".into(), + branch: "HEAD".into(), + active: true, + federate: true, + pinned: true, + }, + Values { + commit: "2d0b363fe3179087de59d9ef4a2d14af21d89071".into(), + url: "https://soniex2.autistic.space/git-repos/chewstuff.git".into(), + branch: "HEAD".into(), + active: true, + federate: true, + pinned: true, + }, + ]); } //#[test] |