diff --git a/checker.go b/checker.go index 15c3d8e..ea785c1 100644 --- a/checker.go +++ b/checker.go @@ -112,8 +112,9 @@ func (c *Checker) isJSON(s string) bool { return false } - if len(s) > 0 { - _, err := strconv.Atoi(s[0:1]) + trimed := strings.TrimSpace(s) + if len(trimed) > 0 { + _, err := strconv.Atoi(trimed[0:1]) if err == nil { return false } diff --git a/golden_test.go b/golden_test.go index 0ad47c5..e07faa1 100644 --- a/golden_test.go +++ b/golden_test.go @@ -29,22 +29,24 @@ func TestDiff(t *testing.T) { got any hasDiff bool }{ - "string-nodiff": {"hello", "hello", false}, - "bytes-nodiff": {"hello", []byte("hello"), false}, - "reader-nodiff": {"hello", strings.NewReader("hello"), false}, - "json-nodiff": {"{\"S\":\"hello\"}\n", struct{ S string }{S: "hello"}, false}, - "marshaler-nodiff": {"hello", marshaler("hello"), false}, - "empty-nodiff": {"", "", false}, - "number-nodiff": {"3", "3", false}, - "number-start-nodiff": {"3 bytes", "3 bytes", false}, + "string-nodiff": {"hello", "hello", false}, + "bytes-nodiff": {"hello", []byte("hello"), false}, + "reader-nodiff": {"hello", strings.NewReader("hello"), false}, + "json-nodiff": {"{\"S\":\"hello\"}\n", struct{ S string }{S: "hello"}, false}, + "marshaler-nodiff": {"hello", marshaler("hello"), false}, + "empty-nodiff": {"", "", false}, + "number-nodiff": {"3", "3", false}, + "number-start-nodiff": {"3 bytes", "3 bytes", false}, + "number-start-with-space-nodiff": {"\n\n \n\r3 bytes", "\n\n \n\r3 bytes", false}, - "string-diff": {"Hello", "hello", true}, - "bytes-diff": {"Hello", []byte("hello"), true}, - "reader-diff": {"Hello", strings.NewReader("hello"), true}, - "json-diff": {"{\"S\":\"Hello\"}\n", struct{ S string }{S: "hello"}, true}, - "marshaler-diff": {"Hello", marshaler("hello"), true}, - "number-diff": {"3", "4", true}, - "number-start-diff": {"3 bytes", "4 bytes", true}, + "string-diff": {"Hello", "hello", true}, + "bytes-diff": {"Hello", []byte("hello"), true}, + "reader-diff": {"Hello", strings.NewReader("hello"), true}, + "json-diff": {"{\"S\":\"Hello\"}\n", struct{ S string }{S: "hello"}, true}, + "marshaler-diff": {"Hello", marshaler("hello"), true}, + "number-diff": {"3", "4", true}, + "number-start-diff": {"3 bytes", "4 bytes", true}, + "number-start-with-space-diff": {"\n\n \n\r3 bytes", "\n\n \n\r4 bytes", true}, } for name, tt := range cases {