-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstrings_test.go
149 lines (132 loc) · 3.51 KB
/
strings_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
// 🤖 Github Repository: https://github.com/gofiber/fiber
// 📌 API Documentation: https://docs.gofiber.io
package utils
import (
"strings"
"testing"
)
func Test_Utils_ToUpper(t *testing.T) {
t.Parallel()
res := ToUpper("/my/name/is/:param/*")
AssertEqual(t, "/MY/NAME/IS/:PARAM/*", res)
}
func Benchmark_ToUpper(b *testing.B) {
var path = "/RePos/GoFiBer/FibEr/iSsues/187643/CoMmEnts"
var res string
b.Run("fiber", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = ToUpper(path)
}
AssertEqual(b, "/REPOS/GOFIBER/FIBER/ISSUES/187643/COMMENTS", res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = strings.ToUpper(path)
}
AssertEqual(b, "/REPOS/GOFIBER/FIBER/ISSUES/187643/COMMENTS", res)
})
}
func Test_Utils_ToLower(t *testing.T) {
t.Parallel()
res := ToLower("/MY/NAME/IS/:PARAM/*")
AssertEqual(t, "/my/name/is/:param/*", res)
res = ToLower("/MY1/NAME/IS/:PARAM/*")
AssertEqual(t, "/my1/name/is/:param/*", res)
res = ToLower("/MY2/NAME/IS/:PARAM/*")
AssertEqual(t, "/my2/name/is/:param/*", res)
res = ToLower("/MY3/NAME/IS/:PARAM/*")
AssertEqual(t, "/my3/name/is/:param/*", res)
res = ToLower("/MY4/NAME/IS/:PARAM/*")
AssertEqual(t, "/my4/name/is/:param/*", res)
}
func Benchmark_ToLower(b *testing.B) {
var path = "/RePos/GoFiBer/FibEr/iSsues/187643/CoMmEnts"
var res string
b.Run("fiber", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = ToLower(path)
}
AssertEqual(b, "/repos/gofiber/fiber/issues/187643/comments", res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = strings.ToLower(path)
}
AssertEqual(b, "/repos/gofiber/fiber/issues/187643/comments", res)
})
}
func Test_Utils_TrimRight(t *testing.T) {
t.Parallel()
res := TrimRight("/test//////", '/')
AssertEqual(t, "/test", res)
res = TrimRight("/test", '/')
AssertEqual(t, "/test", res)
}
func Benchmark_TrimRight(b *testing.B) {
var res string
b.Run("fiber", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = TrimRight("foobar ", ' ')
}
AssertEqual(b, "foobar", res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = strings.TrimRight("foobar ", " ")
}
AssertEqual(b, "foobar", res)
})
}
func Test_Utils_TrimLeft(t *testing.T) {
t.Parallel()
res := TrimLeft("////test/", '/')
AssertEqual(t, "test/", res)
res = TrimLeft("test/", '/')
AssertEqual(t, "test/", res)
}
func Benchmark_TrimLeft(b *testing.B) {
var res string
b.Run("fiber", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = TrimLeft(" foobar", ' ')
}
AssertEqual(b, "foobar", res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = strings.TrimLeft(" foobar", " ")
}
AssertEqual(b, "foobar", res)
})
}
func Test_Utils_Trim(t *testing.T) {
t.Parallel()
res := Trim(" test ", ' ')
AssertEqual(t, "test", res)
res = Trim("test", ' ')
AssertEqual(t, "test", res)
res = Trim(".test", '.')
AssertEqual(t, "test", res)
}
func Benchmark_Trim(b *testing.B) {
var res string
b.Run("fiber", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = Trim(" foobar ", ' ')
}
AssertEqual(b, "foobar", res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = strings.Trim(" foobar ", " ")
}
AssertEqual(b, "foobar", res)
})
b.Run("default.trimspace", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = strings.TrimSpace(" foobar ")
}
AssertEqual(b, "foobar", res)
})
}