show error offsets in tests

This commit is contained in:
Aleksey Kladov 2019-05-29 10:12:08 +03:00
parent 7a1cae59ac
commit 2e722ec54b
46 changed files with 299 additions and 290 deletions

View file

@ -13,7 +13,7 @@ pub struct SyntaxError {
location: Location,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum Location {
Offset(TextUnit),
Range(TextRange),
@ -31,6 +31,15 @@ impl Into<Location> for TextRange {
}
}
impl fmt::Debug for Location {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Location::Offset(it) => fmt::Debug::fmt(it, f),
Location::Range(it) => fmt::Debug::fmt(it, f),
}
}
}
impl SyntaxError {
pub fn new<L: Into<Location>>(kind: SyntaxErrorKind, loc: L) -> SyntaxError {
SyntaxError { kind, location: loc.into() }