Skip to content

Commit

Permalink
Fix panic for custom string type
Browse files Browse the repository at this point in the history
  • Loading branch information
rliebz committed Mar 7, 2024
1 parent 1ca46c5 commit 2ae6fa4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions be/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ want: %v
`,
argGot,
argWant,
quoteString(interface{}(got).(string)),
quoteString(interface{}(want).(string)),
quoteString(reflect.ValueOf(got).String()),
quoteString(reflect.ValueOf(want).String()),
),
}
}
Expand Down
28 changes: 28 additions & 0 deletions be/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ diff (-want +got):
})
}

type CustomString string

func TestEqual(t *testing.T) {
t.Run("equal", func(t *testing.T) {
g := ghost.New(t)
Expand Down Expand Up @@ -310,6 +312,32 @@ diff (-want +got):
result.Message = strings.ReplaceAll(result.Message, "\u00a0", " ")
g.Should(be.Equal(result.Message, wantText))
})

t.Run("custom string type", func(t *testing.T) {
g := ghost.New(t)

type T struct {

Check failure on line 319 in be/assertions_test.go

View workflow job for this annotation

GitHub Actions / lint

type `T` is unused (unused)
A string
B int
}

got := CustomString("foo")
want := CustomString("bar")

result := be.Equal(got, want)
g.Should(be.False(result.Ok))
g.Should(be.Equal(result.Message, `got != want
got: "foo"
want: "bar"
`))

result = be.Equal(CustomString("foo"), CustomString("bar"))
g.Should(be.False(result.Ok))
g.Should(be.Equal(result.Message, `CustomString("foo") != CustomString("bar")
got: "foo"
want: "bar"
`))
})
}

func TestError(t *testing.T) {
Expand Down

0 comments on commit 2ae6fa4

Please sign in to comment.