Skip to content

Commit 2ae6fa4

Browse files
committed
Fix panic for custom string type
1 parent 1ca46c5 commit 2ae6fa4

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

be/assertions.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ want: %v
137137
`,
138138
argGot,
139139
argWant,
140-
quoteString(interface{}(got).(string)),
141-
quoteString(interface{}(want).(string)),
140+
quoteString(reflect.ValueOf(got).String()),
141+
quoteString(reflect.ValueOf(want).String()),
142142
),
143143
}
144144
}

be/assertions_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ diff (-want +got):
146146
})
147147
}
148148

149+
type CustomString string
150+
149151
func TestEqual(t *testing.T) {
150152
t.Run("equal", func(t *testing.T) {
151153
g := ghost.New(t)
@@ -310,6 +312,32 @@ diff (-want +got):
310312
result.Message = strings.ReplaceAll(result.Message, "\u00a0", " ")
311313
g.Should(be.Equal(result.Message, wantText))
312314
})
315+
316+
t.Run("custom string type", func(t *testing.T) {
317+
g := ghost.New(t)
318+
319+
type T struct {
320+
A string
321+
B int
322+
}
323+
324+
got := CustomString("foo")
325+
want := CustomString("bar")
326+
327+
result := be.Equal(got, want)
328+
g.Should(be.False(result.Ok))
329+
g.Should(be.Equal(result.Message, `got != want
330+
got: "foo"
331+
want: "bar"
332+
`))
333+
334+
result = be.Equal(CustomString("foo"), CustomString("bar"))
335+
g.Should(be.False(result.Ok))
336+
g.Should(be.Equal(result.Message, `CustomString("foo") != CustomString("bar")
337+
got: "foo"
338+
want: "bar"
339+
`))
340+
})
313341
}
314342

315343
func TestError(t *testing.T) {

0 commit comments

Comments
 (0)