-
Notifications
You must be signed in to change notification settings - Fork 10
/
bytes_test.go
69 lines (59 loc) · 2.11 KB
/
bytes_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
// ⚡️ 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 (
"bytes"
"testing"
"github.com/stretchr/testify/require"
)
func Test_ToLowerBytes(t *testing.T) {
t.Parallel()
require.Equal(t, []byte("/my/name/is/:param/*"), ToLowerBytes([]byte("/MY/NAME/IS/:PARAM/*")))
require.Equal(t, []byte("/my1/name/is/:param/*"), ToLowerBytes([]byte("/MY1/NAME/IS/:PARAM/*")))
require.Equal(t, []byte("/my2/name/is/:param/*"), ToLowerBytes([]byte("/MY2/NAME/IS/:PARAM/*")))
require.Equal(t, []byte("/my3/name/is/:param/*"), ToLowerBytes([]byte("/MY3/NAME/IS/:PARAM/*")))
require.Equal(t, []byte("/my4/name/is/:param/*"), ToLowerBytes([]byte("/MY4/NAME/IS/:PARAM/*")))
}
func Test_ToUpperBytes(t *testing.T) {
t.Parallel()
require.Equal(t, []byte("/MY/NAME/IS/:PARAM/*"), ToUpperBytes([]byte("/my/name/is/:param/*")))
require.Equal(t, []byte("/MY1/NAME/IS/:PARAM/*"), ToUpperBytes([]byte("/my1/name/is/:param/*")))
require.Equal(t, []byte("/MY2/NAME/IS/:PARAM/*"), ToUpperBytes([]byte("/my2/name/is/:param/*")))
require.Equal(t, []byte("/MY3/NAME/IS/:PARAM/*"), ToUpperBytes([]byte("/my3/name/is/:param/*")))
require.Equal(t, []byte("/MY4/NAME/IS/:PARAM/*"), ToUpperBytes([]byte("/my4/name/is/:param/*")))
}
func Benchmark_ToLowerBytes(b *testing.B) {
path := []byte(largeStr)
want := []byte(lowerStr)
var res []byte
b.Run("fiber", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = ToLowerBytes(path)
}
require.True(b, bytes.Equal(want, res))
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = bytes.ToLower(path)
}
require.True(b, bytes.Equal(want, res))
})
}
func Benchmark_ToUpperBytes(b *testing.B) {
path := []byte(largeStr)
want := []byte(upperStr)
var res []byte
b.Run("fiber", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = ToUpperBytes(path)
}
require.Equal(b, want, res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = bytes.ToUpper(path)
}
require.Equal(b, want, res)
})
}