mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:39:12 +00:00
[red-knot] Add line number to mdtest panic message about language tag mismatch (#16906)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Fixes #16898 ## Test Plan Update test for lang mismatch panic
This commit is contained in:
parent
e4f5fe8cf7
commit
7b86f54c4c
1 changed files with 7 additions and 2 deletions
|
@ -617,8 +617,9 @@ impl<'s> Parser<'s> {
|
|||
.extension()
|
||||
.is_none_or(|extension| extension.eq_ignore_ascii_case(expected_extension))
|
||||
{
|
||||
let backtick_start = self.line_index(backtick_offsets.0);
|
||||
bail!(
|
||||
"File extension of test file path `{explicit_path}` in test `{test_name}` does not match language specified `{lang}` of code block"
|
||||
"File extension of test file path `{explicit_path}` in test `{test_name}` does not match language specified `{lang}` of code block at line `{backtick_start}`"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -750,6 +751,10 @@ impl<'s> Parser<'s> {
|
|||
fn offset(&self) -> TextSize {
|
||||
self.source_len - self.cursor.text_len()
|
||||
}
|
||||
|
||||
fn line_index(&self, char_index: TextSize) -> u32 {
|
||||
self.source.count_lines(TextRange::up_to(char_index))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -1221,7 +1226,7 @@ mod tests {
|
|||
let err = super::parse("file.md", &source).expect_err("Should fail to parse");
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
"File extension of test file path `a.py` in test `Accidental stub` does not match language specified `pyi` of code block"
|
||||
"File extension of test file path `a.py` in test `Accidental stub` does not match language specified `pyi` of code block at line `5`"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue