Skip to content

Commit

Permalink
enable root-level format for primitive-like types (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyab authored May 7, 2024
1 parent 3ea7ad0 commit 5b45adc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion format.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ func (teq Teq) report(expected, actual any) string {
return simple
}
k := ve.Kind()
if k != reflect.Struct &&
_, ok := teq.formats[ve.Type()]
if !ok &&
k != reflect.Struct &&
k != reflect.Map &&
k != reflect.Slice &&
k != reflect.Array &&
Expand Down
25 changes: 25 additions & 0 deletions teq_customized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,31 @@ differences:
}
assert.Equal(t, []string{expected}, mt.errors)
})

t.Run("reflect.Kind", func(t *testing.T) {
tq := teq.New()
tq.AddFormat(func(kind reflect.Kind) string {
return kind.String()
})

mt := &mockT{}
tq.Equal(mt, reflect.Int, reflect.String)
if len(mt.errors) != 1 {
t.Fatalf("expected 1 error, got %d", len(mt.errors))
}
expected := `not equal
differences:
--- expected
+++ actual
@@ -1 +1 @@
-int
+string
`
if mt.errors[0] != expected {
t.Errorf("expected %q, got %q", expected, mt.errors[0])
}
assert.Equal(t, expected, mt.errors[0])
})
}

func utc(d time.Time) time.Time {
Expand Down

0 comments on commit 5b45adc

Please sign in to comment.