Skip to content

Commit 9a15d91

Browse files
authored
Add Token::is_next method (#82)
* adds `Token::is_next method
1 parent c6ceb4b commit 9a15d91

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Adds method `into_buf` for `Box<Pointer>` and `impl From<PathBuf> for Box<Pointer>`.
1414
- Adds unsafe associated methods `Pointer::new_unchecked` and `PointerBuf::new_unchecked` for
1515
external zero-cost construction.
16+
- Adds `Token::is_next` for checking if a token represents the `-` character.
1617

1718
### Changed
1819

src/token.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ impl<'a> Token<'a> {
251251
pub fn to_index(&self) -> Result<Index, ParseIndexError> {
252252
self.try_into()
253253
}
254+
255+
/// Returns if the `Token` is `-`, which stands for the next array index.
256+
///
257+
/// See also [`Self::to_index`].
258+
pub fn is_next(&self) -> bool {
259+
matches!(self.to_index(), Ok(Index::Next))
260+
}
254261
}
255262

256263
macro_rules! impl_from_num {
@@ -491,4 +498,16 @@ mod tests {
491498
]
492499
});
493500
}
501+
502+
#[test]
503+
fn is_next() {
504+
let token = Token::new("-");
505+
assert!(token.is_next());
506+
let token = Token::new("0");
507+
assert!(!token.is_next());
508+
let token = Token::new("a");
509+
assert!(!token.is_next());
510+
let token = Token::new("");
511+
assert!(!token.is_next());
512+
}
494513
}

0 commit comments

Comments
 (0)