modulepackage
0.0.0-20170406064948-c7f18ee00883
Repository: https://github.com/andreyvit/diff.git
Documentation: pkg.go.dev
# README
diff
Quick'n'easy string diffing functions for Golang based on github.com/sergi/go-diff. Mainly for diffing strings in tests.
See the docs on GoDoc.
Get it:
go get -u github.com/andreyvit/diff
Example:
import (
"strings"
"testing"
"github.com/andreyvit/diff"
)
const expected = `
...
`
func TestFoo(t *testing.T) {
actual := Foo(...)
if a, e := strings.TrimSpace(actual), strings.TrimSpace(expected); a != e {
t.Errorf("Result not as expected:\n%v", diff.LineDiff(e, a))
}
}
# Functions
CharacterDiff returns an inline diff between the two strings, using (++added++) and (~~deleted~~) markup.
LineDiff returns a normal linewise diff between the two given strings.
LineDiffAsLines returns the lines of a linewise diff between the two given strings.
TrimLines applies TrimSpace to each string in the given array.
TrimLinesInString applies TrimSpace to each line in the given string, and returns the new trimmed string.