-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils_test.go
58 lines (50 loc) · 1.31 KB
/
utils_test.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package statetrooper
import (
"fmt"
"testing"
)
type CustomStructStringer struct {
Name string
Age int
}
func (cs CustomStructStringer) String() string {
return fmt.Sprintf("CustomStruct - Name: %s", cs.Name)
}
type CustomStruct struct {
Name string
Age int
}
func TestStringable(t *testing.T) {
tests := []struct {
input interface{}
expected bool
}{
{"Nadia", true}, // String type
{42, false}, // Non-string type
{CustomStructStringer{Name: "Yousif"}, true}, // fmt.Stringer type
{CustomStruct{Name: "Jenna"}, false}, // Non-fmt.Stringer type
}
for _, test := range tests {
actual := stringable(test.input)
if actual != test.expected {
t.Errorf("stringable(%v) = %t, expected %t", test.input, actual, test.expected)
}
}
}
func TestToString(t *testing.T) {
tests := []struct {
input interface{}
expected string
}{
{"Nadia", "Nadia"}, // String type
{42, "42"}, // Non-string type
{CustomStructStringer{Name: "Yousif"}, "CustomStruct - Name: Yousif"}, // fmt.Stringer type
{CustomStruct{Name: "Jenna", Age: 12}, "{Jenna 12}"}, // Non-fmt.Stringer type
}
for _, test := range tests {
actual := toString(test.input)
if actual != test.expected {
t.Errorf("toString(%v) = %s, expected %s", test.input, actual, test.expected)
}
}
}