[fine] Type checking bones
This commit is contained in:
parent
5cc9ecc398
commit
c0f40aa512
6 changed files with 613 additions and 3 deletions
|
|
@ -5,10 +5,12 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
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 lines = contents.lines();
|
||||
while let Some(line) = lines.next() {
|
||||
let line = match line.strip_prefix("//") {
|
||||
|
|
@ -29,11 +31,23 @@ fn generate_test_for_file(path: PathBuf) -> String {
|
|||
concrete.push_str("\n");
|
||||
}
|
||||
concrete_stuff = Some(concrete);
|
||||
} else if let Some(line) = line.strip_prefix("type:") {
|
||||
let (pos, expected) = line
|
||||
.trim()
|
||||
.split_once(' ')
|
||||
.expect("Mal-formed type expectation");
|
||||
let pos: usize = pos
|
||||
.trim()
|
||||
.parse()
|
||||
.expect(&format!("Unable to parse position '{pos}'"));
|
||||
let expected = expected.trim();
|
||||
type_assertions.push(quote! {
|
||||
crate::assert_type_at(&_tree, &_lines, #pos, #expected, #display_path);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let concrete_comparison = if let Some(concrete) = concrete_stuff {
|
||||
let display_path = path.display().to_string();
|
||||
quote! {
|
||||
crate::assert_concrete(&_tree, #concrete, #display_path)
|
||||
}
|
||||
|
|
@ -46,6 +60,7 @@ fn generate_test_for_file(path: PathBuf) -> String {
|
|||
fn #name() {
|
||||
let (_tree, _lines) = fine::parser::parse(#contents);
|
||||
#concrete_comparison;
|
||||
#(#type_assertions)*
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue