fix off-by-one error

This commit is contained in:
Folkert 2020-04-01 00:02:25 +02:00
parent 8e8f93955e
commit 6531845966
2 changed files with 40 additions and 1 deletions

View File

@ -294,7 +294,9 @@ impl ReportText {
Region(region) => { Region(region) => {
buf.push('\n'); buf.push('\n');
buf.push('\n'); buf.push('\n');
let max_line_number_length = region.end_line.to_string().len();
// widest displayed line number
let max_line_number_length = (region.end_line + 1).to_string().len();
if region.start_line == region.end_line { if region.start_line == region.end_line {
let i = region.start_line; let i = region.start_line;

View File

@ -621,6 +621,43 @@ mod test_reporting {
); );
} }
#[test]
fn report_region_line_number_length_edge_case() {
// the highest line number is 9, but it's rendered as 10.
// Make sure that we render the line number as 2-wide
report_renders_as_from_src(
indoc!(
r#"
x = 1
y = 2
f = \a -> a + 4
f x
"#
),
to_simple_report(Region(roc_region::all::Region {
start_line: 7,
end_line: 9,
start_col: 0,
end_col: 0,
})),
indoc!(
r#"
8 >
9 > f x
10 >
"#
),
);
}
#[test] #[test]
fn report_region_different_line_number_lengths() { fn report_region_different_line_number_lengths() {
report_renders_as_from_src( report_renders_as_from_src(