feat(test): test all queries
Fallback to default testing for all queries present in the parser's queries directory. For a given query <QUERY>.scm, the test files are searched in test/<QUERY>/* Also mimic the output of other test-running subcommands when testing queries. Co-authored-by: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
This commit is contained in:
parent
b695568516
commit
cc4378e751
3 changed files with 85 additions and 18 deletions
|
|
@ -199,25 +199,33 @@ pub fn parse_position_comments(
|
|||
|
||||
pub fn assert_expected_captures(
|
||||
infos: &[CaptureInfo],
|
||||
path: String,
|
||||
path: &str,
|
||||
parser: &mut Parser,
|
||||
language: &Language,
|
||||
) -> Result<()> {
|
||||
) -> Result<usize> {
|
||||
let contents = fs::read_to_string(path)?;
|
||||
let pairs = parse_position_comments(parser, language, contents.as_bytes())?;
|
||||
for info in infos {
|
||||
if let Some(found) = pairs.iter().find(|p| {
|
||||
p.position.row == info.start.row && p.position >= info.start && p.position < info.end
|
||||
for assertion in &pairs {
|
||||
if let Some(found) = &infos.iter().find(|p| {
|
||||
assertion.position.row == p.start.row
|
||||
&& assertion.position >= p.start
|
||||
&& assertion.position < p.end
|
||||
}) {
|
||||
if found.expected_capture_name != info.name && info.name != "name" {
|
||||
Err(anyhow!(
|
||||
if assertion.expected_capture_name != found.name && found.name != "name" {
|
||||
return Err(anyhow!(
|
||||
"Assertion failed: at {}, found {}, expected {}",
|
||||
info.start,
|
||||
found.expected_capture_name,
|
||||
info.name
|
||||
))?;
|
||||
found.start,
|
||||
assertion.expected_capture_name,
|
||||
found.name
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(anyhow!(
|
||||
"Assertion failed: could not match {} at {}",
|
||||
assertion.expected_capture_name,
|
||||
assertion.position
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
Ok(pairs.len())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue