diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2021-02-13 00:33:52 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2021-02-13 00:33:52 -0300 |
commit | 81a1d3ca72d9f28605bd22687ab20cb61a4ceb1b (patch) | |
tree | 2547d228ab706ace221e51b74a6baf52be625330 /tests | |
parent | abaee464936a821568c3fdbd52b9aadd3adb6d0f (diff) |
Complete the VM, for the most part
Some things are still untested. Needs more tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic_match.rs | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/tests/basic_match.rs b/tests/basic_match.rs index 0b5b546..4697c63 100644 --- a/tests/basic_match.rs +++ b/tests/basic_match.rs @@ -115,33 +115,43 @@ fn test_spaces() { assert!(matcher.next().is_none()); } -//#[test] -//fn test_harder() { -// let tree = Value::M(vec![ -// ("projects".into(), Value::M(vec![ -// ("385e734a52e13949a7a5c71827f6de920dbfea43".into(), Value::M(vec![ -// ("https://soniex2.autistic.space/git-repos/ganarchy.git".into(), Value::M(vec![ -// ("HEAD".into(), Value::M(vec![ -// ("active".into(), Value::B(true)), -// ].into_iter().collect())), -// ].into_iter().collect())), -// ].into_iter().collect())), -// ].into_iter().collect())), -// ].into_iter().collect()); -// let preds = vec![("dict", Box::new(|v: RefOwn<'_, _, _>| matches!(v, RefOwn::Ref(&Value::M(_)))) as Box<datafu::Predicate<Value>>)].into_iter().collect(); -// let pat = datafu::Pattern::<Value>::compile::<_, &str>(" -// -> 'projects'? -// -> commit /[0-9a-fA-F]{40}|[0-9a-fA-F]{64}/? :?$dict -// -> url :?$dict -// -> branch :?$dict", -// Some(preds), -// None, -// ).unwrap(); -// let mut matcher = pat.attempt_match(&tree); -// let m = matcher.next().unwrap().unwrap(); -// assert_eq!(m["commit"].0, RefOwn::Ref(&Value::from("385e734a52e13949a7a5c71827f6de920dbfea43"))); -// assert_eq!(m["url"].0, RefOwn::Ref(&Value::from("https://soniex2.autistic.space/git-repos/ganarchy.git"))); -// assert_eq!(m["branch"].0, RefOwn::Ref(&Value::from("HEAD"))); -// assert_eq!(m["branch"].1, RefOwn::Ref(&Value::M(vec![(Value::from("active"), Value::B(true))].into_iter().collect()))); -// assert!(matcher.next().is_none()); -//} +#[test] +fn test_harder() { + let tree = Value::M(vec![ + ("projects".into(), Value::M(vec![ + ("385e734a52e13949a7a5c71827f6de920dbfea43".into(), Value::M(vec![ + ("https://soniex2.autistic.space/git-repos/ganarchy.git".into(), Value::M(vec![ + ("HEAD".into(), Value::M(vec![ + ("active".into(), Value::B(true)), + ].into_iter().collect())), + ].into_iter().collect())), + ].into_iter().collect())), + ].into_iter().collect())), + ].into_iter().collect()); + let preds = vec![ + ("dict", Box::new(|v: RefOwn<'_, _, _>| matches!(v, RefOwn::Ref(&Value::M(_)))) as Box<datafu::Predicate<Value>>), + ("str", Box::new(|v: RefOwn<'_, _, _>| matches!(v, RefOwn::Ref(&Value::S(_)))) as Box<datafu::Predicate<Value>>), + ("bool", Box::new(|v: RefOwn<'_, _, _>| matches!(v, RefOwn::Ref(&Value::B(_)))) as Box<datafu::Predicate<Value>>), + // stubs, we don't particularly need to test these + ("commit", Box::new(|v: RefOwn<'_, _, _>| matches!(v, RefOwn::Ref(&Value::S(_)))) as Box<datafu::Predicate<Value>>), + ("uri", Box::new(|v: RefOwn<'_, _, _>| matches!(v, RefOwn::Ref(&Value::S(_)))) as Box<datafu::Predicate<Value>>), + ].into_iter().collect(); + let pat = datafu::Pattern::<Value>::compile::<_, &str>(" + ->'projects':$dict + ->commit[:?$str:?$commit]:?$dict + ->url[:?$str:?$uri]:?$dict + ->branch:?$dict + (->active'active'?:?$bool) + (->federate'federate'?:?$bool)?", + Some(preds), + None, + ).unwrap(); + let mut matcher = pat.attempt_match(&tree); + let m = matcher.next().unwrap().unwrap(); + assert_eq!(m["commit"].0, RefOwn::Ref(&Value::from("385e734a52e13949a7a5c71827f6de920dbfea43"))); + assert_eq!(m["url"].0, RefOwn::Ref(&Value::from("https://soniex2.autistic.space/git-repos/ganarchy.git"))); + assert_eq!(m["branch"].0, RefOwn::Ref(&Value::from("HEAD"))); + assert_eq!(m["active"].1, RefOwn::Ref(&Value::B(true))); + assert_eq!(m.get("federate"), None); + assert!(matcher.next().is_none()); +} |