From b3b2032b55cf6c7e660181502004cdb3af4d44b0 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Mon, 15 Jul 2019 07:48:32 +0200 Subject: [PATCH] Fix too many anonymized line numbers This expands the logic for replacing line numbers with `LL` so that line numbers are only replaced, when they are actually provided. When `lineno` is `None`, no `LL` should be shown in the output. --- src/formatter/mod.rs | 2 +- tests/formatter.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/formatter/mod.rs b/src/formatter/mod.rs index eb1392d..654b518 100644 --- a/src/formatter/mod.rs +++ b/src/formatter/mod.rs @@ -303,7 +303,7 @@ impl DisplayListFormatter { inline_marks, line, } => { - let lineno = if self.anonymized_line_numbers { + let lineno = if self.anonymized_line_numbers && lineno.is_some() { Self::ANONYMIZED_LINE_NUM.to_string() } else { self.format_lineno(*lineno, lineno_width) diff --git a/tests/formatter.rs b/tests/formatter.rs index c0bdc11..844c358 100644 --- a/tests/formatter.rs +++ b/tests/formatter.rs @@ -515,13 +515,26 @@ fn test_anon_lines() { range: (0, 19), }, }, + DisplayLine::Source { + lineno: None, + inline_marks: vec![], + line: DisplaySourceLine::Empty, + }, + DisplayLine::Source { + lineno: None, + inline_marks: vec![], + line: DisplaySourceLine::Content { + text: "abc".to_string(), + range: (0, 19), + }, + }, ]); let dlf = DisplayListFormatter::new(false, true); assert_eq!( dlf.format(&dl), - "LL | This is an example\nLL | of content lines" + "LL | This is an example\nLL | of content lines\n |\n | abc" ); }