Skip to content

Commit

Permalink
objectionary#31: implement finds_with_closure test
Browse files Browse the repository at this point in the history
  • Loading branch information
UARTman committed Nov 13, 2022
1 parent 5185b25 commit 54e9a1c
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/ops.rs
Expand Up @@ -337,10 +337,6 @@ impl Sodg {
) -> Result<u32> {
let mut v = v1;
let mut locator: VecDeque<String> = VecDeque::new();
let (head, tail) = {
let mut iter = loc.split('/');
(iter.next().unwrap_or(""), iter.next().unwrap_or(""))
};
loc.split('.')
.filter(|k| !k.is_empty())
.for_each(|k| locator.push_back(k.to_string()));
Expand All @@ -365,7 +361,8 @@ impl Sodg {
v = to;
continue;
};
let other_name = cl(v, head, tail);
let (head, tail) = Self::split_a(&k);
let other_name = cl(v, &head, &tail);
if let Some(to) = self.kid(v, other_name.as_str()) {
trace!("#find: ν{v}.{k} -> ν{to}");
v = to;
Expand Down Expand Up @@ -455,6 +452,30 @@ fn binds_two_names() -> Result<()> {
Ok(())
}

#[test]
fn finds_with_closure() -> Result<()> {
let mut g = Sodg::empty();
g.add(1)?;
g.add(2)?;
g.add(3)?;
g.bind(1, 2, "first")?;
g.bind(2, 3, "something_else")?;
assert_eq!(
3,
g.find_with_closure(1, "first.second/abc", |v, head, tail| {
if v == 1 && !tail.is_empty() {
panic!();
}
if v == 2 && head == "second" && tail == "abc" {
"something_else".to_string()
} else {
"".to_string()
}
})?
);
Ok(())
}

#[rstest]
#[case("hello", "hello")]
#[case("hello/a.b.c", "hello")]
Expand Down

0 comments on commit 54e9a1c

Please sign in to comment.