mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55:47 +02:00
Fix ForEachLineInFile to not lose the last line if it doesn't end with a LF
This commit is contained in:
parent
b71aa5e23b
commit
696e78fcc8
3 changed files with 2 additions and 11 deletions
|
@ -52,9 +52,6 @@ var ResolveWithoutTrailingLf = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
Contains("M file").IsSelected(),
|
Contains("M file").IsSelected(),
|
||||||
)
|
)
|
||||||
|
|
||||||
/* EXPECTED:
|
|
||||||
t.Views().Main().Content(Contains("-a1\n+a2\n").DoesNotContain("-no eol"))
|
t.Views().Main().Content(Contains("-a1\n+a2\n").DoesNotContain("-no eol"))
|
||||||
ACTUAL: */
|
|
||||||
t.Views().Main().Content(Contains("-a1\n+a2\n").Contains("-no eol"))
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -21,8 +21,8 @@ func ForEachLineInFile(path string, f func(string, int)) error {
|
||||||
func forEachLineInStream(reader io.Reader, f func(string, int)) {
|
func forEachLineInStream(reader io.Reader, f func(string, int)) {
|
||||||
bufferedReader := bufio.NewReader(reader)
|
bufferedReader := bufio.NewReader(reader)
|
||||||
for i := 0; true; i++ {
|
for i := 0; true; i++ {
|
||||||
line, err := bufferedReader.ReadString('\n')
|
line, _ := bufferedReader.ReadString('\n')
|
||||||
if err != nil {
|
if len(line) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
f(line, i)
|
f(line, i)
|
||||||
|
|
|
@ -26,10 +26,7 @@ func Test_forEachLineInStream(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "single line without line feed",
|
name: "single line without line feed",
|
||||||
input: "abc",
|
input: "abc",
|
||||||
/* EXPECTED:
|
|
||||||
expectedLines: []string{"abc"},
|
expectedLines: []string{"abc"},
|
||||||
ACTUAL: */
|
|
||||||
expectedLines: []string{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multiple lines",
|
name: "multiple lines",
|
||||||
|
@ -44,10 +41,7 @@ func Test_forEachLineInStream(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "multiple lines without linefeed at end of file",
|
name: "multiple lines without linefeed at end of file",
|
||||||
input: "abc\ndef\nghi",
|
input: "abc\ndef\nghi",
|
||||||
/* EXPECTED:
|
|
||||||
expectedLines: []string{"abc\n", "def\n", "ghi"},
|
expectedLines: []string{"abc\n", "def\n", "ghi"},
|
||||||
ACTUAL: */
|
|
||||||
expectedLines: []string{"abc\n", "def\n"},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue