[red-knot] Report line numbers in mdtest relative to the markdown file, not the test snippet (#13804)

Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: Carl Meyer <carl@oddbird.net>
This commit is contained in:
aditya pillai 2024-10-22 03:42:40 -04:00 committed by GitHub
parent 9d102799f9
commit cd6c937194
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 130 additions and 53 deletions

View file

@ -26,6 +26,16 @@ impl<'a> Cursor<'a> {
self.chars.clone()
}
/// Returns the remaining input as byte slice.
pub fn as_bytes(&self) -> &'a [u8] {
self.as_str().as_bytes()
}
/// Returns the remaining input as string slice.
pub fn as_str(&self) -> &'a str {
self.chars.as_str()
}
/// Peeks the next character from the input stream without consuming it.
/// Returns [`EOF_CHAR`] if the file is at the end of the file.
pub fn first(&self) -> char {
@ -110,4 +120,13 @@ impl<'a> Cursor<'a> {
self.bump_back();
}
}
/// Skips the next `count` bytes.
///
/// ## Panics
/// - If `count` is larger than the remaining bytes in the input stream.
/// - If `count` indexes into a multi-byte character.
pub fn skip_bytes(&mut self, count: usize) {
self.chars = self.chars.as_str()[count..].chars();
}
}