diff --git a/main_test.go b/main_test.go index bf45536..49da8eb 100644 --- a/main_test.go +++ b/main_test.go @@ -23,6 +23,7 @@ import ( "path/filepath" "strings" "testing" + "unicode/utf8" "github.com/sergi/go-diff/diffmatchpatch" ) @@ -196,6 +197,25 @@ func TestMinimalError(t *testing.T) { // TODO(sbarzowski) test pretty errors once they are stable-ish // probably "golden" pattern is the right one for that +func removeExcessiveWhitespace(s string) string { + var buf bytes.Buffer + separated := true + for i, w := 0, 0; i < len(s); i += w { + runeValue, width := utf8.DecodeRuneInString(s[i:]) + if runeValue == '\n' || runeValue == ' ' { + if !separated { + buf.WriteString(" ") + separated = true + } + } else { + buf.WriteRune(runeValue) + separated = false + } + w = width + } + return buf.String() +} + func TestCustomImporter(t *testing.T) { vm := MakeVM() vm.Importer(&MemoryImporter{