INNER CODE UNIT · Go
firstDifference
xo/usql · cli_test.go:236
func firstDifference(want, got string) string {
wantLines, gotLines := splitLines(want), splitLines(got)
for i := 0; i < len(wantLines) && i < len(gotLines); i++ {
if wantLines[i] != gotLines[i] {
return fmt.Sprintf("line %d:\n want: %q\n got: %q", i+1, wantLines[i], gotLines[i])
}
}
return fmt.Sprintf("the recordings agree for %d lines, then the lengths differ: want %d lines, got %d",
min(len(wantLines), len(gotLines)), len(wantLines), len(gotLines))
}
// splitLines splits s on newlines without dropping a trailing empty line.
func splitLines(s string) []string {
var out []string
start := 0
for i := 0; i < len(s); i++ {
if s[i] == '\n' {
out = append(out, s[start:i])