lib/scanner: add tokens! > variant for matching Results
This commit is contained in:
parent
2768e5c86c
commit
3a93cb006a
|
@ -28,6 +28,14 @@ macro_rules! tokens {
|
||||||
(@unwrap @ $scanner:expr => $expected:expr $(=> $msg:tt)? ) => {
|
(@unwrap @ $scanner:expr => $expected:expr $(=> $msg:tt)? ) => {
|
||||||
assert_eq!($scanner.next().transpose()?, $expected $(, $msg)? )
|
assert_eq!($scanner.next().transpose()?, $expected $(, $msg)? )
|
||||||
};
|
};
|
||||||
|
(@unwrap > $scanner:expr => $expected:expr $(=> $msg:tt)? ) => {
|
||||||
|
let event = $scanner
|
||||||
|
.next()
|
||||||
|
.ok_or_else(
|
||||||
|
|| anyhow::anyhow!("Unexpected end of tokens, was expecting: {:?} ~{}", $expected, $scanner.buffer)
|
||||||
|
)?;
|
||||||
|
assert_eq!(event, $expected $(, $msg)? )
|
||||||
|
};
|
||||||
// Forward to option assert any unknown sigils
|
// Forward to option assert any unknown sigils
|
||||||
(@unwrap $any:tt $scanner:expr => $expected:expr $(=> $msg:tt)? ) => {
|
(@unwrap $any:tt $scanner:expr => $expected:expr $(=> $msg:tt)? ) => {
|
||||||
tokens!(@unwrap @ $scanner:expr => $expected:expr $(=> $msg)? )
|
tokens!(@unwrap @ $scanner:expr => $expected:expr $(=> $msg)? )
|
||||||
|
@ -36,16 +44,18 @@ macro_rules! tokens {
|
||||||
(@token $scanner:expr => $expected:expr) => {
|
(@token $scanner:expr => $expected:expr) => {
|
||||||
let event = $scanner
|
let event = $scanner
|
||||||
.next()
|
.next()
|
||||||
|
.map(|r| r.map_err(|e| anyhow::anyhow!("{} ~{}", e, $scanner.buffer)))
|
||||||
.ok_or_else(
|
.ok_or_else(
|
||||||
|| anyhow::anyhow!("Unexpected end of tokens, was expecting: {:?} ~{}", $expected, $scanner.buffer)
|
|| anyhow::anyhow!("Unexpected end of tokens, was expecting: {:?} ~{}", $expected, $scanner.buffer)
|
||||||
)??;
|
)??;
|
||||||
|
|
||||||
assert_eq!(event, $expected)
|
assert_eq!(event, $expected)
|
||||||
};
|
};
|
||||||
// Variant for token assert, no with message
|
// Variant for token assert, with message
|
||||||
(@token $scanner:expr => $expected:expr, $msg:tt) => {
|
(@token $scanner:expr => $expected:expr, $msg:tt) => {
|
||||||
let event = $scanner
|
let event = $scanner
|
||||||
.next()
|
.next()
|
||||||
|
.map(|r| r.map_err(|e| anyhow::anyhow!("{} ~{}", e, $scanner.buffer)))
|
||||||
.ok_or_else(
|
.ok_or_else(
|
||||||
|| anyhow::anyhow!("Unexpected end of tokens, {}: {:?} ~{}", $msg, $expected, $scanner.buffer)
|
|| anyhow::anyhow!("Unexpected end of tokens, {}: {:?} ~{}", $msg, $expected, $scanner.buffer)
|
||||||
)??;
|
)??;
|
||||||
|
|
Loading…
Reference in a new issue