Skip to content

Commit 9133749

Browse files
test: add ut for util_test (#2840)
Signed-off-by: rfyiamcool <[email protected]> Co-authored-by: ofekshenawa <[email protected]>
1 parent 51897bc commit 9133749

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

internal/util_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package internal
2+
3+
import (
4+
"strings"
5+
"testing"
6+
7+
. "github.com/bsm/ginkgo/v2"
8+
. "github.com/bsm/gomega"
9+
)
10+
11+
func BenchmarkToLowerStd(b *testing.B) {
12+
str := "AaBbCcDdEeFfGgHhIiJjKk"
13+
for i := 0; i < b.N; i++ {
14+
_ = strings.ToLower(str)
15+
}
16+
}
17+
18+
// util.ToLower is 3x faster than strings.ToLower.
19+
func BenchmarkToLowerInternal(b *testing.B) {
20+
str := "AaBbCcDdEeFfGgHhIiJjKk"
21+
for i := 0; i < b.N; i++ {
22+
_ = ToLower(str)
23+
}
24+
}
25+
26+
func TestToLower(t *testing.T) {
27+
It("toLower", func() {
28+
str := "AaBbCcDdEeFfGg"
29+
Expect(ToLower(str)).To(Equal(strings.ToLower(str)))
30+
31+
str = "ABCDE"
32+
Expect(ToLower(str)).To(Equal(strings.ToLower(str)))
33+
34+
str = "ABCDE"
35+
Expect(ToLower(str)).To(Equal(strings.ToLower(str)))
36+
37+
str = "abced"
38+
Expect(ToLower(str)).To(Equal(strings.ToLower(str)))
39+
})
40+
}
41+
42+
func TestIsLower(t *testing.T) {
43+
It("isLower", func() {
44+
str := "AaBbCcDdEeFfGg"
45+
Expect(isLower(str)).To(BeFalse())
46+
47+
str = "ABCDE"
48+
Expect(isLower(str)).To(BeFalse())
49+
50+
str = "abcdefg"
51+
Expect(isLower(str)).To(BeTrue())
52+
})
53+
}

0 commit comments

Comments
 (0)