Created
March 1, 2016 17:26
-
-
Save bprosnitz/60d93bdcc53d8148b8f9 to your computer and use it in GitHub Desktop.
Helper to diff lines for debugging multi-line output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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