Skip to content

Commit

Permalink
fix(reporter): Only inc the line count if we haven't already done so …
Browse files Browse the repository at this point in the history
…with '\n' or '\r\n' (#37)
  • Loading branch information
felipesere committed Aug 29, 2021
1 parent 53f5d6d commit 5a47437
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/printer/graphical_printer.rs
Expand Up @@ -461,6 +461,7 @@ impl GraphicalReportPrinter {
let mut lines = Vec::new();
while let Some(char) = iter.next() {
offset += char.len_utf8();
let mut at_end_of_file = false;
match char {
'\r' => {
if iter.next_if_eq(&'\n').is_some() {
Expand All @@ -471,8 +472,10 @@ impl GraphicalReportPrinter {
line_str.push(char);
column += 1;
}
at_end_of_file = iter.peek().is_none();
}
'\n' => {
at_end_of_file = iter.peek().is_none();
line += 1;
column = 0;
}
Expand All @@ -481,7 +484,8 @@ impl GraphicalReportPrinter {
column += 1;
}
}
if iter.peek().is_none() {

if iter.peek().is_none() && !at_end_of_file {
line += 1;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/printer.rs
Expand Up @@ -277,7 +277,7 @@ line5
3 │ ││ line3
4 │ │├─▶ line4
· │╰──── block 2
6 │ ├──▶ line5
5 │ ├──▶ line5
· ╰───── block 1
‽ try doing it better next time?
Expand Down Expand Up @@ -329,7 +329,7 @@ line5
2 │ │╭─▶ line2
3 │ ││ line3
4 │ │╰─▶ line4
6 │ ├──▶ line5
5 │ ├──▶ line5
· ╰───── block 1
‽ try doing it better next time?
Expand Down

0 comments on commit 5a47437

Please sign in to comment.