Macro-ize token tests

This commit is contained in:
greg 2016-01-09 00:07:48 -08:00
parent e436533638
commit 8c65ae3214
1 changed files with 18 additions and 3 deletions

View File

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