mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Region with line numbers of different string length need to pad shorter line numbers
This commit is contained in:
parent
4cec4d2c8a
commit
1478fbca3f
2 changed files with 53 additions and 6 deletions
|
@ -165,13 +165,25 @@ impl ReportText {
|
||||||
}
|
}
|
||||||
Type(content) => buf.push_str(content_to_string(content, subs, home, interns).as_str()),
|
Type(content) => buf.push_str(content_to_string(content, subs, home, interns).as_str()),
|
||||||
Region(region) => {
|
Region(region) => {
|
||||||
|
let max_line_number_length = region.end_line.to_string().len();
|
||||||
|
|
||||||
for i in region.start_line..=region.end_line {
|
for i in region.start_line..=region.end_line {
|
||||||
buf.push_str(i.to_string().as_str());
|
let i_one_indexed = i + 1;
|
||||||
|
|
||||||
|
let line_number_string = i_one_indexed.to_string();
|
||||||
|
let line_number = line_number_string.as_str();
|
||||||
|
let this_line_number_length = line_number.len();
|
||||||
|
|
||||||
|
buf.push_str(
|
||||||
|
" ".repeat(max_line_number_length - this_line_number_length)
|
||||||
|
.as_str(),
|
||||||
|
);
|
||||||
|
buf.push_str(line_number);
|
||||||
buf.push_str(" ┆");
|
buf.push_str(" ┆");
|
||||||
|
|
||||||
let line = src_lines[i as usize];
|
let line = src_lines[i as usize];
|
||||||
|
|
||||||
if !line.is_empty() {
|
if !line.trim().is_empty() {
|
||||||
buf.push_str(" ");
|
buf.push_str(" ");
|
||||||
buf.push_str(src_lines[i as usize]);
|
buf.push_str(src_lines[i as usize]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,7 @@ mod test_report {
|
||||||
r#"
|
r#"
|
||||||
y is not used anywhere in your code.
|
y is not used anywhere in your code.
|
||||||
|
|
||||||
1 ┆ y = 2
|
2 ┆ y = 2
|
||||||
|
|
||||||
If you didn't intend on using y then remove it so future readers of your code don't wonder why it is there."#
|
If you didn't intend on using y then remove it so future readers of your code don't wonder why it is there."#
|
||||||
)
|
)
|
||||||
|
@ -276,9 +276,44 @@ mod test_report {
|
||||||
})),
|
})),
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
1 ┆ y = 2
|
2 ┆ y = 2
|
||||||
2 ┆ f = \a -> a + 4
|
3 ┆ f = \a -> a + 4
|
||||||
3 ┆"#
|
4 ┆"#
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn report_region_different_line_number_lengths() {
|
||||||
|
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: 8,
|
||||||
|
end_line: 10,
|
||||||
|
start_col: 0,
|
||||||
|
end_col: 0,
|
||||||
|
})),
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
9 ┆
|
||||||
|
10 ┆ y = 2
|
||||||
|
11 ┆ f = \a -> a + 4"#
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue