From aa266f059ddb0751793aa56b4ed2fae2ad591fa5 Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Thu, 24 Mar 2022 07:15:23 +0700 Subject: [PATCH] some tests --- crates/main/src/main.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/main/src/main.rs b/crates/main/src/main.rs index 75b98d7..34c1b7d 100644 --- a/crates/main/src/main.rs +++ b/crates/main/src/main.rs @@ -75,7 +75,6 @@ fn main() { std::process::exit(1); } } - dbg!(check(&ir)); // Report lowering errors if any if diagnostics.has_error() { @@ -113,3 +112,40 @@ fn main() { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_lexer() { + let src = " + let x: int = 1; + "; + + let (tokens, lex_error) = lex(src.to_string()); + assert!(lex_error.is_empty()); + + assert_eq!(tokens.unwrap().len(), 7); + } + + #[test] + fn test_parser() { + let src = " + fun main (foo: int) (bar: bool): string = do + do + let x: int = foo + 1; + end; + let y: bool = bar; + end; + "; + + let (tokens, lex_error) = lex(src.to_string()); + assert!(lex_error.is_empty()); + + let (ast, parse_error) = parse(tokens.unwrap(), src.chars().count()); + assert!(parse_error.is_empty()); + + assert!(ast.is_some()); + } +} \ No newline at end of file