-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
89 lines (80 loc) · 1.79 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package tabber
import (
"testing"
)
func TestEqual(t *testing.T) {
tests := []struct {
name string
v1 int
v2 int
want bool
}{
{"Equal", 10, 10, true},
{"NotEqual", 5, 10, false},
{"NegativeValues", -5, -5, true},
{"MixedSign", -5, 5, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := equal(tt.v1, tt.v2)
if got != tt.want {
t.Errorf("Equal() = %v, want %v", got, tt.want)
}
})
}
}
func TestIntToString(t *testing.T) {
tests := []struct {
name string
value int
want string
}{
{"PositiveNumber", 10, "10"},
{"Zero", 0, "0"},
{"NegativeNumber", -5, "-5"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := intToString(tt.value)
if got != tt.want {
t.Errorf("IntToString() = %v, want %v", got, tt.want)
}
})
}
}
func TestTrimmed(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"\"hello\"", "hello"},
{"\"world\"", "world"},
{"\"\"", ""},
{"hello", "hello"}, // no quotes, no change expected
}
for _, test := range tests {
result := trimmed(test.input)
if result != test.expected {
t.Errorf("Trimmed(%s) = %s; expected %s", test.input, result, test.expected)
}
}
}
func TestToSlug(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"New Resource", "new-resource"},
{"Another_Resource", "another-resource"},
{"Multiple Spaces", "multiple--spaces"},
{"Capital Letters", "capital-letters"},
{"\"With Quotes\"", "with-quotes"}, // quotes should be removed
{"", ""}, // empty string should remain empty
}
for _, test := range tests {
result := toSlug(test.input)
if result != test.expected {
t.Errorf("ToSlug(%s) = %s; expected %s", test.input, result, test.expected)
}
}
}