-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_test.go
More file actions
40 lines (34 loc) · 739 Bytes
/
string_test.go
File metadata and controls
40 lines (34 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package refutil
import "testing"
type testStinger struct{}
func (s *testStinger) String() string {
return "stringer"
}
type testStinger2 struct{}
func (s testStinger2) String() string {
return "stringer"
}
func TestString(t *testing.T) {
x := "test"
x2 := &testStinger{}
tests := []struct {
x interface{}
expected string
}{
{"1", "1"},
{&x, "test"},
{&x2, "stringer"},
{&testStinger{}, "stringer"},
{testStinger2{}, "stringer"},
{map[string]string{}, "map[]"},
{nil, ""},
{(*string)(nil), ""},
}
for _, tt := range tests {
t.Run("test can indirect type", func(t *testing.T) {
if got := String(tt.x); got != tt.expected {
t.Errorf("String() = %v, want %v", got, tt.expected)
}
})
}
}