Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable root-level format for primitive-like types #11

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading