Add simple parsing test

This commit is contained in:
greg 2015-08-06 04:24:24 -07:00
parent 79619025ea
commit a947ec3cb2

View File

@ -68,6 +68,7 @@ pub fn parse(input: Vec<Token>) -> ParseResult {
return ParseResult::Ok(AST::Statements(vec!())); return ParseResult::Ok(AST::Statements(vec!()));
} }
match statements(&mut tokens) { match statements(&mut tokens) {
ok@ParseResult::Ok(_) => { ok@ParseResult::Ok(_) => {
expect!(EOF, &mut tokens); 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()); 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)
}
}
}