Added some tests

And commented out old tests for Maaru that don't compile
This commit is contained in:
greg 2017-09-08 02:43:03 -07:00
parent 74f8c16599
commit 737dad6438
3 changed files with 23 additions and 3 deletions

View File

@ -635,6 +635,7 @@ pub fn parse(tokens: &[Token], _parsed_tree: &[Statement]) -> ParseResult<AST> {
parser.program() parser.program()
} }
/*
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use schala_lang::tokenizer; use schala_lang::tokenizer;
@ -751,3 +752,4 @@ mod tests {
} }
} }
} }
*/

View File

@ -139,6 +139,7 @@ fn tokenize_identifier(c: char, iter: &mut Peekable<Chars>) -> Result<Token, Tok
}) })
} }
/*
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@ -204,3 +205,4 @@ mod tests {
} }
} }
*/

View File

@ -8,7 +8,7 @@ use self::itertools::Itertools;
use std::str::Chars; use std::str::Chars;
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Debug)] #[derive(Debug, PartialEq)]
pub enum TokenType { pub enum TokenType {
Newline, Semicolon, Newline, Semicolon,
@ -29,7 +29,7 @@ pub enum TokenType {
Error(String), Error(String),
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum Kw { pub enum Kw {
If, Else, If, Else,
Func, Func,
@ -92,7 +92,6 @@ pub fn tokenize(input: &str) -> Vec<Token> {
let mut input: CharIter = input.chars().enumerate().peekable(); let mut input: CharIter = input.chars().enumerate().peekable();
while let Some((idx, c)) = input.next() { while let Some((idx, c)) = input.next() {
println!("C: {}", c);
let cur_tok_type = match c { let cur_tok_type = match c {
'#' => { '#' => {
if let Some(&(_, '{')) = input.peek() { if let Some(&(_, '{')) = input.peek() {
@ -202,6 +201,23 @@ fn handle_operator(c: char, input: &mut CharIter) -> TokenType {
TokenType::Operator(Rc::new(buf)) 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<B> = c ++ d");
let token_types: Vec<TokenType> = 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 Schala EBNF grammar