autogenerate test suite

This commit is contained in:
Moritz Gmeiner 2024-09-02 15:35:28 +02:00
commit 274faf1e0a
7 changed files with 332 additions and 1732 deletions

File diff suppressed because it is too large Load diff

View file

@ -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();

File diff suppressed because it is too large Load diff

View file

@ -1,3 +0,0 @@
// [line 3] Error: Unexpected character.
// [java line 3] Error at 'b': Expect ')' after arguments.
foo(a | b);

View file

@ -1,3 +1,3 @@
fun foo(a) {
var a; // Error at 'a': Already a variable with this name in this scope.
var a;
}