request_test: Point out first difference in marshalled string

This commit is contained in:
Aaron Lindsay 2017-03-31 20:16:44 -04:00
parent 3fa614b649
commit 1cbd433116
1 changed files with 8 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package ofxgo_test
import (
"github.com/aclindsa/ofxgo"
"regexp"
"strings"
"testing"
)
@ -27,15 +28,21 @@ func marshalCheckRequest(t *testing.T, request *ofxgo.Request, expected string)
for i := 0; i < compareLength; i++ {
if expectedString[i] != actualString[i] {
firstDifferencePosition := 13
displayStart := i - 10
prefix := "..."
suffix := "..."
if displayStart < 0 {
prefix = ""
firstDifferencePosition = i
displayStart = 0
}
displayEnd := displayStart + 40
if displayEnd > compareLength {
suffix = ""
displayEnd = compareLength
}
t.Fatalf("%s expected '...%s...',\ngot '...%s...'\n", t.Name(), expectedString[displayStart:displayEnd], actualString[displayStart:displayEnd])
t.Fatalf("%s expected '%s%s%s',\ngot '%s%s%s'\n %s^ first difference\n", t.Name(), prefix, expectedString[displayStart:displayEnd], suffix, prefix, actualString[displayStart:displayEnd], suffix, strings.Repeat(" ", firstDifferencePosition))
}
}