Skip to content

Commit

Permalink
Merge pull request #23 from wngr/main
Browse files Browse the repository at this point in the history
`Pointer::last` return `None` for root pointer
  • Loading branch information
chanced authored Mar 4, 2024
2 parents 4b13aff + c0744b7 commit c17a55d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ impl Pointer {
}
/// Returns the last `Token` in the `Pointer`.
pub fn back(&self) -> Option<Token> {
if self.is_root() {
return None;
}
self.inner[1..]
.rsplit_once('/')
.map_or(Some((&self.inner[1..], "")), Option::Some)
Expand Down Expand Up @@ -1398,7 +1401,14 @@ mod tests {

let ptr = Pointer::try_from("/-").unwrap();
assert_eq!(ptr.last(), Some("-".into()));

let ptr = Pointer::default();
assert_eq!(ptr.last(), None);

let ptr = Pointer::try_from("/bar").unwrap();
assert_eq!(ptr.last(), Some("bar".into()));
}

#[test]
fn test_first() {
let ptr = Pointer::try_from("/foo/bar").unwrap();
Expand Down

0 comments on commit c17a55d

Please sign in to comment.