From 737dad643811e60345bfd3246c526bf704417332 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 8 Sep 2017 02:43:03 -0700 Subject: [PATCH] Added some tests And commented out old tests for Maaru that don't compile --- src/maaru_lang/parser.rs | 2 ++ src/maaru_lang/tokenizer.rs | 2 ++ src/schala_lang/parsing.rs | 22 +++++++++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/maaru_lang/parser.rs b/src/maaru_lang/parser.rs index bb094f6..74f5987 100644 --- a/src/maaru_lang/parser.rs +++ b/src/maaru_lang/parser.rs @@ -635,6 +635,7 @@ pub fn parse(tokens: &[Token], _parsed_tree: &[Statement]) -> ParseResult { parser.program() } +/* #[cfg(test)] mod tests { use schala_lang::tokenizer; @@ -751,3 +752,4 @@ mod tests { } } } +*/ diff --git a/src/maaru_lang/tokenizer.rs b/src/maaru_lang/tokenizer.rs index 1147e81..ad979e1 100644 --- a/src/maaru_lang/tokenizer.rs +++ b/src/maaru_lang/tokenizer.rs @@ -139,6 +139,7 @@ fn tokenize_identifier(c: char, iter: &mut Peekable) -> Result Vec { let mut input: CharIter = input.chars().enumerate().peekable(); while let Some((idx, c)) = input.next() { - println!("C: {}", c); let cur_tok_type = match c { '#' => { if let Some(&(_, '{')) = input.peek() { @@ -202,6 +201,23 @@ fn handle_operator(c: char, input: &mut CharIter) -> TokenType { TokenType::Operator(Rc::new(buf)) } +#[cfg(test)] +mod schala_tokenizer_tests { + use super::*; + use super::TokenType::*; + use super::Kw::*; + + macro_rules! ident { ($ident:expr) => { Identifier(Rc::new($ident.to_string())) } } + macro_rules! op { ($ident:expr) => { Operator(Rc::new($ident.to_string())) } } + + #[test] + fn tokens() { + let a = tokenize("let a: A = c ++ d"); + let token_types: Vec = a.into_iter().map(move |t| t.token_type).collect(); + assert_eq!(token_types, vec![Keyword(Let), ident!("a"), Colon, ident!("A"), + LAngleBracket, ident!("B"), RAngleBracket, op!("="), ident!("c"), op!("++"), ident!("d")]); + } +} /* Schala EBNF grammar