From a947ec3cb2c86bb536796217986c178856686d23 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 6 Aug 2015 04:24:24 -0700 Subject: [PATCH] Add simple parsing test --- src/parser.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index de57f41..e36015a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -68,6 +68,7 @@ pub fn parse(input: Vec) -> ParseResult { return ParseResult::Ok(AST::Statements(vec!())); } + match statements(&mut tokens) { ok@ParseResult::Ok(_) => { expect!(EOF, &mut tokens); @@ -263,3 +264,20 @@ fn simple_expression(tokens: &mut Tokens) -> ParseResult { return ParseResult::Err("Bad parse in simple_expression()".to_string()); } + +#[cfg(test)] +mod tests { + use super::*; + use tokenizer::tokenize; + + #[test] + fn parse_tests() { + ::init_binop_table(); + + match parse(tokenize("a + b * c")) { + ParseResult::Ok(ast) => + assert_eq!(format!("{:?}", ast), "Statements([BinOp(Name(\"+\"), Name(\"a\"), BinOp(Name(\"*\"), Name(\"b\"), Name(\"c\")))])"), + ParseResult::Err(err) => panic!("err: {:?}", err) + } + } +}