From c52fd4c73d16eeb95b53b99fabc14af8aa39cc41 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 11 Sep 2017 03:21:07 -0700 Subject: [PATCH] Parse test --- src/schala_lang/parsing.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index e73a3e0..9d2c426 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -302,6 +302,7 @@ digits := (digit_group underscore)+ type TokenIter = Peekable>; +#[derive(Debug)] pub struct ParseError { pub msg: String, } @@ -341,7 +342,7 @@ macro_rules! expect { } } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct AST(Vec); #[derive(Debug, PartialEq)] @@ -469,3 +470,16 @@ pub fn parse(input: Vec) -> Result { let mut parser = Parser::new(input); parser.program() } + +#[cfg(test)] +mod parse_tests { + use super::*; + use super::Statement::*; + use super::Expression::*; + use super::ParseError; + #[test] + fn test_parsing() { + let a = "8.1"; + assert_eq!(parse(tokenize(a)).unwrap(), AST(vec![Expression(FloatLiteral(8.1))])); + } +}