Fix line count off-by-one error

Signed-off-by: Simon Alling <alling.simon@gmail.com>
pull/9677/head
Simon Alling 4 years ago
parent cfd06bbd74
commit 96c39548b4

@ -91,8 +91,8 @@ func AssertGoldenStringWithCustomLineValidation(t TestingT, checkLine func(expec
if err != nil { if err != nil {
t.Fatalf("%v", err) t.Fatalf("%v", err)
} }
expectedLines := strings.Split(string(normalize(expectedOutput)), "\n") expectedLines := lines(expectedOutput)
actualLines := strings.Split(string(normalize([]byte(actualOutput))), "\n") actualLines := lines([]byte(actualOutput))
expectedLineCount := len(expectedLines) expectedLineCount := len(expectedLines)
actualLineCount := len(actualLines) actualLineCount := len(actualLines)
for i := 0; i < max(expectedLineCount, actualLineCount); i++ { for i := 0; i < max(expectedLineCount, actualLineCount); i++ {
@ -118,6 +118,10 @@ func AssertGoldenStringWithCustomLineValidation(t TestingT, checkLine func(expec
} }
} }
func lines(raw []byte) []string {
return strings.Split(strings.TrimSuffix(string(normalize(raw)), "\n"), "\n") // We first remove the final newline (if any), so that e.g. the 2-line string "a\nb\n" is mapped to ["a", "b"] and not ["a", "b", ""].
}
func path(filename string) string { func path(filename string) string {
if filepath.IsAbs(filename) { if filepath.IsAbs(filename) {
return filename return filename

Loading…
Cancel
Save