mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-23 21:51:07 +02:00
Factor out into NormalizeLinefeeds; add tests
This commit is contained in:
parent
b46d174f70
commit
cea736e6e9
@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/spkg/bom"
|
"github.com/spkg/bom"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -218,8 +219,7 @@ func (gui *Gui) renderString(g *gocui.Gui, viewName, s string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
v.Clear()
|
v.Clear()
|
||||||
output := string(bom.Clean([]byte(s)))
|
output := utils.NormalizeLinefeeds(string(bom.Clean([]byte(s))))
|
||||||
output = strings.Replace(output, "\r", "\r\n", -1)
|
|
||||||
fmt.Fprint(v, output)
|
fmt.Fprint(v, output)
|
||||||
v.Wrap = true
|
v.Wrap = true
|
||||||
return nil
|
return nil
|
||||||
|
@ -63,3 +63,9 @@ func TrimTrailingNewline(str string) string {
|
|||||||
}
|
}
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NormalizeLinefeeds(str string) string {
|
||||||
|
str = strings.Replace(str, "\r\n", "\n", -1)
|
||||||
|
str = strings.Replace(str, "\r", "\n", -1)
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
34
pkg/utils/utils_test.go
Normal file
34
pkg/utils/utils_test.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
var testCases = []struct {
|
||||||
|
Input []byte
|
||||||
|
Expected []byte
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
// \r\n
|
||||||
|
Input: []byte{97, 115, 100, 102, 13, 10},
|
||||||
|
Expected: []byte{97, 115, 100, 102, 10},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// \r
|
||||||
|
Input: []byte{97, 115, 100, 102, 13},
|
||||||
|
Expected: []byte{97, 115, 100, 102, 10},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// \n
|
||||||
|
Input: []byte{97, 115, 100, 102, 10},
|
||||||
|
Expected: []byte{97, 115, 100, 102, 10},
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNormalizeLinefeeds(t *testing.T) {
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
if NormalizeLinefeeds(string(tc.Input)) != string(tc.Expected) {
|
||||||
|
t.Error("Error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,18 @@ set -ex; rm -rf repo; mkdir repo; cd repo
|
|||||||
|
|
||||||
git init
|
git init
|
||||||
|
|
||||||
|
cat <<EOT >> windowslf.txt
|
||||||
|
asdf
|
||||||
|
asdf
|
||||||
|
EOT
|
||||||
|
|
||||||
|
unix2dos windowslf.txt
|
||||||
|
|
||||||
|
cat <<EOT >> linuxlf.txt
|
||||||
|
asdf
|
||||||
|
asdf
|
||||||
|
EOT
|
||||||
|
|
||||||
cat <<EOT >> bomtest.txt
|
cat <<EOT >> bomtest.txt
|
||||||
A,B,C,D,E
|
A,B,C,D,E
|
||||||
F,G,H,I,J
|
F,G,H,I,J
|
||||||
|
Loading…
x
Reference in New Issue
Block a user