@@ -7,20 +7,18 @@ package utils
7
7
import (
8
8
"bytes"
9
9
"testing"
10
+
11
+ "github.com/stretchr/testify/require"
10
12
)
11
13
12
14
func Test_ToLowerBytes (t * testing.T ) {
13
15
t .Parallel ()
14
- res := ToLowerBytes ([]byte ("/MY/NAME/IS/:PARAM/*" ))
15
- AssertEqual (t , true , bytes .Equal ([]byte ("/my/name/is/:param/*" ), res ))
16
- res = ToLowerBytes ([]byte ("/MY1/NAME/IS/:PARAM/*" ))
17
- AssertEqual (t , true , bytes .Equal ([]byte ("/my1/name/is/:param/*" ), res ))
18
- res = ToLowerBytes ([]byte ("/MY2/NAME/IS/:PARAM/*" ))
19
- AssertEqual (t , true , bytes .Equal ([]byte ("/my2/name/is/:param/*" ), res ))
20
- res = ToLowerBytes ([]byte ("/MY3/NAME/IS/:PARAM/*" ))
21
- AssertEqual (t , true , bytes .Equal ([]byte ("/my3/name/is/:param/*" ), res ))
22
- res = ToLowerBytes ([]byte ("/MY4/NAME/IS/:PARAM/*" ))
23
- AssertEqual (t , true , bytes .Equal ([]byte ("/my4/name/is/:param/*" ), res ))
16
+
17
+ require .Equal (t , []byte ("/my/name/is/:param/*" ), ToLowerBytes ([]byte ("/MY/NAME/IS/:PARAM/*" )))
18
+ require .Equal (t , []byte ("/my1/name/is/:param/*" ), ToLowerBytes ([]byte ("/MY1/NAME/IS/:PARAM/*" )))
19
+ require .Equal (t , []byte ("/my2/name/is/:param/*" ), ToLowerBytes ([]byte ("/MY2/NAME/IS/:PARAM/*" )))
20
+ require .Equal (t , []byte ("/my3/name/is/:param/*" ), ToLowerBytes ([]byte ("/MY3/NAME/IS/:PARAM/*" )))
21
+ require .Equal (t , []byte ("/my4/name/is/:param/*" ), ToLowerBytes ([]byte ("/MY4/NAME/IS/:PARAM/*" )))
24
22
}
25
23
26
24
func Benchmark_ToLowerBytes (b * testing.B ) {
@@ -31,28 +29,24 @@ func Benchmark_ToLowerBytes(b *testing.B) {
31
29
for n := 0 ; n < b .N ; n ++ {
32
30
res = ToLowerBytes (path )
33
31
}
34
- AssertEqual (b , bytes .Equal (want , res ), true )
32
+ require . Equal (b , bytes .Equal (want , res ), true )
35
33
})
36
34
b .Run ("default" , func (b * testing.B ) {
37
35
for n := 0 ; n < b .N ; n ++ {
38
36
res = bytes .ToLower (path )
39
37
}
40
- AssertEqual (b , bytes .Equal (want , res ), true )
38
+ require . Equal (b , bytes .Equal (want , res ), true )
41
39
})
42
40
}
43
41
44
42
func Test_ToUpperBytes (t * testing.T ) {
45
43
t .Parallel ()
46
- res := ToUpperBytes ([]byte ("/my/name/is/:param/*" ))
47
- AssertEqual (t , true , bytes .Equal ([]byte ("/MY/NAME/IS/:PARAM/*" ), res ))
48
- res = ToUpperBytes ([]byte ("/my1/name/is/:param/*" ))
49
- AssertEqual (t , true , bytes .Equal ([]byte ("/MY1/NAME/IS/:PARAM/*" ), res ))
50
- res = ToUpperBytes ([]byte ("/my2/name/is/:param/*" ))
51
- AssertEqual (t , true , bytes .Equal ([]byte ("/MY2/NAME/IS/:PARAM/*" ), res ))
52
- res = ToUpperBytes ([]byte ("/my3/name/is/:param/*" ))
53
- AssertEqual (t , true , bytes .Equal ([]byte ("/MY3/NAME/IS/:PARAM/*" ), res ))
54
- res = ToUpperBytes ([]byte ("/my4/name/is/:param/*" ))
55
- AssertEqual (t , true , bytes .Equal ([]byte ("/MY4/NAME/IS/:PARAM/*" ), res ))
44
+
45
+ require .Equal (t , []byte ("/MY/NAME/IS/:PARAM/*" ), ToUpperBytes ([]byte ("/my/name/is/:param/*" )))
46
+ require .Equal (t , []byte ("/MY1/NAME/IS/:PARAM/*" ), ToUpperBytes ([]byte ("/my1/name/is/:param/*" )))
47
+ require .Equal (t , []byte ("/MY2/NAME/IS/:PARAM/*" ), ToUpperBytes ([]byte ("/my2/name/is/:param/*" )))
48
+ require .Equal (t , []byte ("/MY3/NAME/IS/:PARAM/*" ), ToUpperBytes ([]byte ("/my3/name/is/:param/*" )))
49
+ require .Equal (t , []byte ("/MY4/NAME/IS/:PARAM/*" ), ToUpperBytes ([]byte ("/my4/name/is/:param/*" )))
56
50
}
57
51
58
52
func Benchmark_ToUpperBytes (b * testing.B ) {
@@ -63,156 +57,12 @@ func Benchmark_ToUpperBytes(b *testing.B) {
63
57
for n := 0 ; n < b .N ; n ++ {
64
58
res = ToUpperBytes (path )
65
59
}
66
- AssertEqual (b , bytes . Equal ( want , res ), true )
60
+ require . Equal (b , want , res )
67
61
})
68
62
b .Run ("default" , func (b * testing.B ) {
69
63
for n := 0 ; n < b .N ; n ++ {
70
64
res = bytes .ToUpper (path )
71
65
}
72
- AssertEqual (b , bytes .Equal (want , res ), true )
73
- })
74
- }
75
-
76
- func Test_TrimRightBytes (t * testing.T ) {
77
- t .Parallel ()
78
- res := TrimRightBytes ([]byte ("/test//////" ), '/' )
79
- AssertEqual (t , []byte ("/test" ), res )
80
-
81
- res = TrimRightBytes ([]byte ("/test" ), '/' )
82
- AssertEqual (t , []byte ("/test" ), res )
83
-
84
- res = TrimRightBytes ([]byte (" " ), ' ' )
85
- AssertEqual (t , 0 , len (res ))
86
-
87
- res = TrimRightBytes ([]byte (" " ), ' ' )
88
- AssertEqual (t , 0 , len (res ))
89
-
90
- res = TrimRightBytes ([]byte ("" ), ' ' )
91
- AssertEqual (t , 0 , len (res ))
92
- }
93
-
94
- func Benchmark_TrimRightBytes (b * testing.B ) {
95
- var res []byte
96
-
97
- b .Run ("fiber" , func (b * testing.B ) {
98
- for n := 0 ; n < b .N ; n ++ {
99
- res = TrimRightBytes ([]byte ("foobar " ), ' ' )
100
- }
101
- AssertEqual (b , []byte ("foobar" ), res )
102
- })
103
- b .Run ("default" , func (b * testing.B ) {
104
- for n := 0 ; n < b .N ; n ++ {
105
- res = bytes .TrimRight ([]byte ("foobar " ), " " )
106
- }
107
- AssertEqual (b , []byte ("foobar" ), res )
108
- })
109
- }
110
-
111
- func Test_TrimLeftBytes (t * testing.T ) {
112
- t .Parallel ()
113
- res := TrimLeftBytes ([]byte ("////test/" ), '/' )
114
- AssertEqual (t , []byte ("test/" ), res )
115
-
116
- res = TrimLeftBytes ([]byte ("test/" ), '/' )
117
- AssertEqual (t , []byte ("test/" ), res )
118
-
119
- res = TrimLeftBytes ([]byte (" " ), ' ' )
120
- AssertEqual (t , 0 , len (res ))
121
-
122
- res = TrimLeftBytes ([]byte (" " ), ' ' )
123
- AssertEqual (t , 0 , len (res ))
124
-
125
- res = TrimLeftBytes ([]byte ("" ), ' ' )
126
- AssertEqual (t , 0 , len (res ))
127
- }
128
-
129
- func Benchmark_TrimLeftBytes (b * testing.B ) {
130
- var res []byte
131
-
132
- b .Run ("fiber" , func (b * testing.B ) {
133
- for n := 0 ; n < b .N ; n ++ {
134
- res = TrimLeftBytes ([]byte (" foobar" ), ' ' )
135
- }
136
- AssertEqual (b , []byte ("foobar" ), res )
66
+ require .Equal (b , want , res )
137
67
})
138
- b .Run ("default" , func (b * testing.B ) {
139
- for n := 0 ; n < b .N ; n ++ {
140
- res = bytes .TrimLeft ([]byte (" foobar" ), " " )
141
- }
142
- AssertEqual (b , []byte ("foobar" ), res )
143
- })
144
- }
145
-
146
- func Test_TrimBytes (t * testing.T ) {
147
- t .Parallel ()
148
- res := TrimBytes ([]byte (" test " ), ' ' )
149
- AssertEqual (t , []byte ("test" ), res )
150
-
151
- res = TrimBytes ([]byte ("test" ), ' ' )
152
- AssertEqual (t , []byte ("test" ), res )
153
-
154
- res = TrimBytes ([]byte (".test" ), '.' )
155
- AssertEqual (t , []byte ("test" ), res )
156
-
157
- res = TrimBytes ([]byte (" " ), ' ' )
158
- AssertEqual (t , 0 , len (res ))
159
-
160
- res = TrimBytes ([]byte (" " ), ' ' )
161
- AssertEqual (t , 0 , len (res ))
162
-
163
- res = TrimBytes ([]byte ("" ), ' ' )
164
- AssertEqual (t , 0 , len (res ))
165
- }
166
-
167
- func Benchmark_TrimBytes (b * testing.B ) {
168
- var res []byte
169
-
170
- b .Run ("fiber" , func (b * testing.B ) {
171
- for n := 0 ; n < b .N ; n ++ {
172
- res = TrimBytes ([]byte (" foobar " ), ' ' )
173
- }
174
- AssertEqual (b , []byte ("foobar" ), res )
175
- })
176
- b .Run ("default" , func (b * testing.B ) {
177
- for n := 0 ; n < b .N ; n ++ {
178
- res = bytes .Trim ([]byte (" foobar " ), " " )
179
- }
180
- AssertEqual (b , []byte ("foobar" ), res )
181
- })
182
- }
183
-
184
- func Benchmark_EqualFoldBytes (b * testing.B ) {
185
- left := []byte (upperStr )
186
- right := []byte (lowerStr )
187
- var res bool
188
- b .Run ("fiber" , func (b * testing.B ) {
189
- for n := 0 ; n < b .N ; n ++ {
190
- res = EqualFoldBytes (left , right )
191
- }
192
- AssertEqual (b , true , res )
193
- })
194
- b .Run ("default" , func (b * testing.B ) {
195
- for n := 0 ; n < b .N ; n ++ {
196
- res = bytes .EqualFold (left , right )
197
- }
198
- AssertEqual (b , true , res )
199
- })
200
- }
201
-
202
- func Test_EqualFoldBytes (t * testing.T ) {
203
- t .Parallel ()
204
- res := EqualFoldBytes ([]byte ("/MY/NAME/IS/:PARAM/*" ), []byte ("/my/name/is/:param/*" ))
205
- AssertEqual (t , true , res )
206
- res = EqualFoldBytes ([]byte ("/MY1/NAME/IS/:PARAM/*" ), []byte ("/MY1/NAME/IS/:PARAM/*" ))
207
- AssertEqual (t , true , res )
208
- res = EqualFoldBytes ([]byte ("/my2/name/is/:param/*" ), []byte ("/my2/name" ))
209
- AssertEqual (t , false , res )
210
- res = EqualFoldBytes ([]byte ("/dddddd" ), []byte ("eeeeee" ))
211
- AssertEqual (t , false , res )
212
- res = EqualFoldBytes ([]byte ("\n a" ), []byte ("*A" ))
213
- AssertEqual (t , false , res )
214
- res = EqualFoldBytes ([]byte ("/MY3/NAME/IS/:PARAM/*" ), []byte ("/my3/name/is/:param/*" ))
215
- AssertEqual (t , true , res )
216
- res = EqualFoldBytes ([]byte ("/MY4/NAME/IS/:PARAM/*" ), []byte ("/my4/nAME/IS/:param/*" ))
217
- AssertEqual (t , true , res )
218
68
}
0 commit comments