From 3a93cb006a8ddfc41063b97a512f0a278bc6188c Mon Sep 17 00:00:00 2001 From: Bazaah Date: Sat, 5 Jun 2021 17:00:39 +0000 Subject: [PATCH] lib/scanner: add tokens! > variant for matching Results --- src/scanner/tests/macros.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/scanner/tests/macros.rs b/src/scanner/tests/macros.rs index 604ecef..64c57d5 100644 --- a/src/scanner/tests/macros.rs +++ b/src/scanner/tests/macros.rs @@ -28,6 +28,14 @@ macro_rules! tokens { (@unwrap @ $scanner:expr => $expected:expr $(=> $msg:tt)? ) => { 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 (@unwrap $any:tt $scanner:expr => $expected:expr $(=> $msg:tt)? ) => { tokens!(@unwrap @ $scanner:expr => $expected:expr $(=> $msg)? ) @@ -36,16 +44,18 @@ macro_rules! tokens { (@token $scanner:expr => $expected:expr) => { let event = $scanner .next() + .map(|r| r.map_err(|e| anyhow::anyhow!("{} ~{}", e, $scanner.buffer))) .ok_or_else( || anyhow::anyhow!("Unexpected end of tokens, was expecting: {:?} ~{}", $expected, $scanner.buffer) )??; assert_eq!(event, $expected) }; - // Variant for token assert, no with message + // Variant for token assert, with message (@token $scanner:expr => $expected:expr, $msg:tt) => { let event = $scanner .next() + .map(|r| r.map_err(|e| anyhow::anyhow!("{} ~{}", e, $scanner.buffer))) .ok_or_else( || anyhow::anyhow!("Unexpected end of tokens, {}: {:?} ~{}", $msg, $expected, $scanner.buffer) )??;