Skip to content

Commit 696e78f

Browse files
committed
Fix ForEachLineInFile to not lose the last line if it doesn't end with a LF
1 parent b71aa5e commit 696e78f

File tree

3 files changed

+2
-11
lines changed

3 files changed

+2
-11
lines changed

pkg/integration/tests/conflicts/resolve_without_trailing_lf.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ var ResolveWithoutTrailingLf = NewIntegrationTest(NewIntegrationTestArgs{
5252
Contains("M file").IsSelected(),
5353
)
5454

55-
/* EXPECTED:
5655
t.Views().Main().Content(Contains("-a1\n+a2\n").DoesNotContain("-no eol"))
57-
ACTUAL: */
58-
t.Views().Main().Content(Contains("-a1\n+a2\n").Contains("-no eol"))
5956
},
6057
})

pkg/utils/io.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ func ForEachLineInFile(path string, f func(string, int)) error {
2121
func forEachLineInStream(reader io.Reader, f func(string, int)) {
2222
bufferedReader := bufio.NewReader(reader)
2323
for i := 0; true; i++ {
24-
line, err := bufferedReader.ReadString('\n')
25-
if err != nil {
24+
line, _ := bufferedReader.ReadString('\n')
25+
if len(line) == 0 {
2626
break
2727
}
2828
f(line, i)

pkg/utils/io_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ func Test_forEachLineInStream(t *testing.T) {
2626
{
2727
name: "single line without line feed",
2828
input: "abc",
29-
/* EXPECTED:
3029
expectedLines: []string{"abc"},
31-
ACTUAL: */
32-
expectedLines: []string{},
3330
},
3431
{
3532
name: "multiple lines",
@@ -44,10 +41,7 @@ func Test_forEachLineInStream(t *testing.T) {
4441
{
4542
name: "multiple lines without linefeed at end of file",
4643
input: "abc\ndef\nghi",
47-
/* EXPECTED:
4844
expectedLines: []string{"abc\n", "def\n", "ghi"},
49-
ACTUAL: */
50-
expectedLines: []string{"abc\n", "def\n"},
5145
},
5246
}
5347

0 commit comments

Comments
 (0)