[fine] Assignments!
And new error capabilities!
This commit is contained in:
parent
92cf840766
commit
f20f5a5e03
12 changed files with 400 additions and 64 deletions
|
|
@ -1,8 +1,25 @@
|
|||
use quote::{format_ident, quote};
|
||||
use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream};
|
||||
use quote::{format_ident, quote, TokenStreamExt};
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
struct ExpectedErrors(Vec<String>);
|
||||
|
||||
impl quote::ToTokens for ExpectedErrors {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
let mut inner = TokenStream::new();
|
||||
for err in self.0.iter() {
|
||||
inner.append(Literal::string(err));
|
||||
inner.append(Punct::new(',', Spacing::Alone));
|
||||
}
|
||||
|
||||
tokens.append(Ident::new("vec", Span::call_site()));
|
||||
tokens.append(Punct::new('!', Spacing::Joint));
|
||||
tokens.append(Group::new(Delimiter::Parenthesis, inner))
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_test_for_file(path: PathBuf) -> String {
|
||||
let contents = fs::read_to_string(&path)
|
||||
.expect("Unable to read input")
|
||||
|
|
@ -92,6 +109,21 @@ fn generate_test_for_file(path: PathBuf) -> String {
|
|||
assertions.push(quote! {
|
||||
crate::assert_check_error(&_tree, &_lines, #expected);
|
||||
});
|
||||
} else if line == "@expect-errors:" {
|
||||
let mut errors = Vec::new();
|
||||
while let Some(line) = lines.next() {
|
||||
let line = match line.strip_prefix("// | ") {
|
||||
Some(line) => line,
|
||||
None => break,
|
||||
};
|
||||
|
||||
errors.push(line.to_string());
|
||||
}
|
||||
|
||||
let errors = ExpectedErrors(errors);
|
||||
assertions.push(quote! {
|
||||
crate::assert_errors(&_tree, &_lines, #errors);
|
||||
});
|
||||
} else if line.starts_with("@") {
|
||||
panic!("Test file {display_path} has unknown directive: {line}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue