Skip to content

Commit

Permalink
#60: Fix find_with_closure
Browse files Browse the repository at this point in the history
It now uses `self.find` on the closure result.
  • Loading branch information
UARTman committed Jan 10, 2023
1 parent ff25c44 commit 66cca34
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ impl Sodg {
};
let (head, tail) = Self::split_a(&k);
let redirect = cl(v, &head, &tail, self)?;
if let Some(to) = self.kid(v, redirect.as_str()) {
if let Ok(to) = self.find(v, redirect.as_str()) {
trace!("#find: ν{v}.{k} -> ν{to} (redirect to {redirect})");
v = to;
continue;
};
}
let others: Vec<String> = self
.vertices
.get(&v)
Expand Down Expand Up @@ -621,3 +621,20 @@ fn replaces_ignoring_locator() -> Result<()> {
assert_eq!(1, g.kids(0)?.len());
Ok(())
}

#[test]
fn finds_absolute_coordinates() {
let mut g = Sodg::empty();
g.add(0).unwrap();
g.add(1).unwrap();
g.bind(0, 1, "foo").unwrap();
assert!(g.find(0, "bar").is_err());
let v = g
.find_with_closure(0, "bar", |_v, a, b, _| {
assert_eq!(a, "bar");
assert_eq!(b, "");
Ok("ν1".to_string())
})
.unwrap();
assert_eq!(1, v);
}

0 comments on commit 66cca34

Please sign in to comment.