From 1cbd433116374637befeccefe7e5e030ba28aac3 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 31 Mar 2017 20:16:44 -0400 Subject: [PATCH] request_test: Point out first difference in marshalled string --- request_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/request_test.go b/request_test.go index b1d9531..a546e42 100644 --- a/request_test.go +++ b/request_test.go @@ -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)) } }