[fine] Tests for type errors
WHEEEEEEE!
This commit is contained in:
parent
618e0028d3
commit
a9c1b04920
8 changed files with 123 additions and 47 deletions
|
|
@ -7,10 +7,8 @@ fn generate_test_for_file(path: PathBuf) -> String {
|
|||
let contents = fs::read_to_string(&path).expect("Unable to read input");
|
||||
let display_path = path.display().to_string();
|
||||
|
||||
let mut concrete_stuff: Option<String> = None;
|
||||
|
||||
// Start iterating over lines and processing directives....
|
||||
let mut type_assertions = Vec::new();
|
||||
let mut assertions = Vec::new();
|
||||
let mut lines = contents.lines();
|
||||
while let Some(line) = lines.next() {
|
||||
let line = match line.strip_prefix("//") {
|
||||
|
|
@ -30,7 +28,10 @@ fn generate_test_for_file(path: PathBuf) -> String {
|
|||
concrete.push_str(line);
|
||||
concrete.push_str("\n");
|
||||
}
|
||||
concrete_stuff = Some(concrete);
|
||||
|
||||
assertions.push(quote! {
|
||||
crate::assert_concrete(&_tree, #concrete, #display_path);
|
||||
});
|
||||
} else if let Some(line) = line.strip_prefix("type:") {
|
||||
let (pos, expected) = line
|
||||
.trim()
|
||||
|
|
@ -41,26 +42,30 @@ fn generate_test_for_file(path: PathBuf) -> String {
|
|||
.parse()
|
||||
.expect(&format!("Unable to parse position '{pos}'"));
|
||||
let expected = expected.trim();
|
||||
type_assertions.push(quote! {
|
||||
assertions.push(quote! {
|
||||
crate::assert_type_at(&_tree, &_lines, #pos, #expected, #display_path);
|
||||
});
|
||||
} else if let Some(line) = line.strip_prefix("type-error:") {
|
||||
let (pos, expected) = line
|
||||
.trim()
|
||||
.split_once(' ')
|
||||
.expect("Mal-formed type-error expectation");
|
||||
let pos: usize = pos
|
||||
.trim()
|
||||
.parse()
|
||||
.expect(&format!("Unable to parse position '{pos}'"));
|
||||
let expected = expected.trim();
|
||||
assertions.push(quote! {
|
||||
crate::assert_type_error_at(&_tree, &_lines, #pos, #expected, #display_path);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let concrete_comparison = if let Some(concrete) = concrete_stuff {
|
||||
quote! {
|
||||
crate::assert_concrete(&_tree, #concrete, #display_path)
|
||||
}
|
||||
} else {
|
||||
quote! {}
|
||||
};
|
||||
|
||||
let name = format_ident!("{}", path.file_stem().unwrap().to_string_lossy());
|
||||
let test_method = quote! {
|
||||
fn #name() {
|
||||
let (_tree, _lines) = fine::parser::parse(#contents);
|
||||
#concrete_comparison;
|
||||
#(#type_assertions)*
|
||||
#(#assertions)*
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue