mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 23:37:56 +03:00
fix off-by-one error
This commit is contained in:
parent
8e8f93955e
commit
6531845966
@ -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;
|
||||||
|
@ -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(
|
||||||
|
Loading…
Reference in New Issue
Block a user