Skip to content

Instantly share code, notes, and snippets.

@bprosnitz
Created March 1, 2016 17:26
Show Gist options
  • Save bprosnitz/60d93bdcc53d8148b8f9 to your computer and use it in GitHub Desktop.
Save bprosnitz/60d93bdcc53d8148b8f9 to your computer and use it in GitHub Desktop.
Helper to diff lines for debugging multi-line output
func diffLines(a, b string) {
fmt.Printf("len(a) %d len(b) %d\n", len(a), len(b))
sa := bufio.NewScanner(strings.NewReader(a))
sb := bufio.NewScanner(strings.NewReader(b))
index := 0
for {
index++
var readSomething bool
var aline string
var bline string
if sa.Scan() {
aline = sa.Text()
readSomething = true
}
if sb.Scan() {
bline = sb.Text()
readSomething = true
}
if !readSomething {
break
}
if aline != bline {
fmt.Printf("%4d:\ngot:\n%s\nwant:\n%s\n", index, aline, bline)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment