Skip to content

Commit

Permalink
Fix display implementation for DUMMY_SPAN
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscInside committed Dec 6, 2024
1 parent 07fde0e commit e7e358e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ast/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Debug for Span {
impl Display for Span {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let start = self.0.get_location(self.1);
let end = self.0.get_location((self.2 - 1).max(self.1));
let end = self.0.get_location((self.2.saturating_sub(1)).max(self.1));
let quote = self.string();
match (&self.0.name, start.line == end.line) {
(Some(filename), true) => write!(
Expand Down Expand Up @@ -886,10 +886,17 @@ pub enum ParseError {

#[cfg(test)]
mod tests {
use crate::DUMMY_SPAN;

#[test]
fn test_parser_display_roundtrip() {
let s = r#"(f (g a 3) 4.0 (H "hello"))"#;
let e = crate::ast::parse_expr(None, s).unwrap();
assert_eq!(format!("{}", e), s);
}

#[test]
fn dummy_span_display() {
assert_eq!(format!("{}", DUMMY_SPAN.clone()), "In 1:1-1: ");
}
}

0 comments on commit e7e358e

Please sign in to comment.