- added more unit tests for lexer

- corrected defects revealed by added tests
This commit is contained in:
Aidan 2021-01-24 22:04:26 -08:00
parent e4f2fbaa70
commit 172aa4ea4b
No known key found for this signature in database
GPG key ID: 327711E983899316
3 changed files with 113 additions and 77 deletions

View file

@ -2,13 +2,47 @@ mod lex_tests {
use relish::ast::{lex};
#[test]
fn test_lex_basic_list() {
let document: &str = "(hello \"world\")";
fn test_lex_basic_pair() {
let document: &str = "(hello 'world')";
let output: &str = "(hello 'world' nil)";
match lex(document.to_string()) {
Ok(box_cell) => {
assert_eq!(format!("{}", *box_cell), document.to_string());
assert_eq!(format!("{}", *box_cell), output.to_string());
},
Err(_s) => assert!(false)
Err(s) => {
print!("{}\n", s);
assert!(false);
}
}
}
#[test]
fn test_lex_basic_list() {
let document: &str = "(hello 'world' 1 2 3)";
let output: &str = "(hello 'world' 1 2 3 nil)";
match lex(document.to_string()) {
Ok(box_cell) => {
assert_eq!(format!("{}", *box_cell), output.to_string());
},
Err(s) => {
print!("{}\n", s);
assert!(false);
}
}
}
#[test]
fn test_lex_complex_list() {
let document: &str = "(hello 'world' (1 2 (1 2 3)) 1 2 3)";
let output: &str = "(hello 'world' (1 2 (1 2 3 nil) nil) 1 2 3 nil)";
match lex(document.to_string()) {
Ok(box_cell) => {
assert_eq!(format!("{}", *box_cell), output.to_string());
},
Err(s) => {
print!("{}\n", s);
assert!(false);
}
}
}
}