1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

some tests

This commit is contained in:
Natapat Samutpong 2022-03-24 07:15:23 +07:00
parent ea90b7f90a
commit aa266f059d

View file

@ -75,7 +75,6 @@ fn main() {
std::process::exit(1); std::process::exit(1);
} }
} }
dbg!(check(&ir));
// Report lowering errors if any // Report lowering errors if any
if diagnostics.has_error() { 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());
}
}