Skip to content

Commit

Permalink
Support for comparison with JSON acquired with string type
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Mar 4, 2024
1 parent 55dbde2 commit 8fd7ff2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *Checker) Check(suffix string, data any) (diff string) {
defer golden.Close()

wantStr := readAll(c.testingT, c.JSONIdent, golden)
if c.isBytes(data) || !c.isJSON(wantStr) {
if c.isBytesOrString(data) || !c.isJSON(wantStr) {
gotStr := readAll(c.testingT, c.JSONIdent, data)
return cmp.Diff(wantStr, gotStr, c.opts...)
}
Expand Down Expand Up @@ -123,11 +123,15 @@ func (c *Checker) isJSON(s string) bool {
return true
}

func (c *Checker) isBytes(v any) bool {
func (c *Checker) isBytesOrString(v any) bool {
c.testingT.Helper()

_, ok := v.([]byte)
return ok
switch v.(type) {

Check failure on line 128 in checker.go

View workflow job for this annotation

GitHub Actions / test

type Decoder,Delim,Encoder,InvalidUTF8Error,InvalidUnmarshalError,MarshalerError,Number,RawMessage,SyntaxError,UnmarshalFieldError,UnmarshalTypeError,UnsupportedTypeError,UnsupportedValueError,encoding/json.decodeState,encoding/json.errorContext,encoding/json.scanner does not appear in any cases
case []byte:
return true
case string:
return true
}
return false
}

func (c *Checker) updateFile(path string, data any) {
Expand Down

0 comments on commit 8fd7ff2

Please sign in to comment.