Macro-ize token tests

This commit is contained in:
greg 2016-01-09 00:07:48 -08:00
parent e436533638
commit 8c65ae3214

View File

@ -124,13 +124,28 @@ pub fn tokenize(input: &str) -> Option<Vec<Token>> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
macro_rules! tokentest {
($input:expr, $output:expr) => {
{
let tokens = tokenize($input).unwrap();
assert_eq!(format!("{:?}", tokens), $output);
}
}
}
use super::*; use super::*;
#[test] #[test]
fn tokeniziation_tests() { fn tokeniziation_tests() {
let input1 = "let a = 3\n"; tokentest!("let a = 3\n",
let token1 = tokenize(input1).unwrap();
assert_eq!(format!("{:?}", token1),
"[Identifier(\"let\"), Identifier(\"a\"), Identifier(\"=\"), NumLiteral(3), Newline, EOF]"); "[Identifier(\"let\"), Identifier(\"a\"), Identifier(\"=\"), NumLiteral(3), Newline, EOF]");
tokentest!("2+1",
"[NumLiteral(2), Identifier(\"+\"), NumLiteral(1), EOF]");
tokentest!("2 + 1",
"[NumLiteral(2), Identifier(\"+\"), NumLiteral(1), EOF]");
} }
} }