mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 12:22:42 +00:00
autogenerate test suite
This commit is contained in:
parent
76bf3a2a07
commit
274faf1e0a
7 changed files with 332 additions and 1732 deletions
|
|
@ -8,6 +8,8 @@ use rlox2_interpreter::{run, Runtime};
|
|||
|
||||
#[cfg(test)]
|
||||
pub fn run_test(path: impl Into<PathBuf>) {
|
||||
use smol_str::SmolStr;
|
||||
|
||||
let path = &path.into();
|
||||
// path.insert_str(0, "./tests/lox/");
|
||||
|
||||
|
|
@ -15,25 +17,29 @@ pub fn run_test(path: impl Into<PathBuf>) {
|
|||
|
||||
let tokens = rlox2_frontend::lexer::scan_tokens(&source).unwrap();
|
||||
|
||||
let comments: Vec<String> = tokens
|
||||
.into_iter()
|
||||
.filter_map(|token| {
|
||||
let comments: Result<Vec<String>, SmolStr> =
|
||||
tokens.into_iter().try_fold(Vec::new(), |mut acc, token| {
|
||||
if let TokenType::Comment(s) = token.token_type {
|
||||
if s.starts_with(" expect: ") {
|
||||
Some(s.strip_prefix(" expect: ").unwrap().trim().to_owned())
|
||||
} else if s.contains("Error") || s.contains("error") {
|
||||
Some(s.trim().into())
|
||||
} else {
|
||||
None
|
||||
if s.contains("Error") || s.contains("error") {
|
||||
return Err(s);
|
||||
} else if s.starts_with(" expect: ") {
|
||||
acc.push(s.trim().strip_prefix("expect:").unwrap().trim().to_owned());
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
for comment in comments.iter() {
|
||||
println!("Comment: \"{comment}\"")
|
||||
Ok(acc)
|
||||
});
|
||||
|
||||
match comments {
|
||||
Ok(ref comments) => {
|
||||
println!("Expecting positive result");
|
||||
for comment in comments.iter() {
|
||||
println!("Comment: \"{comment}\"")
|
||||
}
|
||||
}
|
||||
Err(ref e) => {
|
||||
println!("Expecting error: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
print!("\n\n");
|
||||
|
|
@ -51,17 +57,17 @@ pub fn run_test(path: impl Into<PathBuf>) {
|
|||
Err(e) => {
|
||||
println!("{e}");
|
||||
|
||||
assert_eq!(comments.len(), 1);
|
||||
|
||||
let comment = &*comments[0];
|
||||
|
||||
assert!(comment.to_lowercase().contains("error"));
|
||||
assert!(comments.is_err());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let Ok(comments) = comments else {
|
||||
panic!("Positive outcome, but expected error");
|
||||
};
|
||||
|
||||
let mut output = output.as_ref().borrow_mut();
|
||||
let output = String::from_utf8(std::mem::take(&mut *output)).unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue