test: add ut for util_test (#2840)

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
This commit is contained in:
fengyun.rui 2024-02-15 04:16:50 +08:00 committed by GitHub
parent 51897bc5bf
commit 9133749cd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 53 additions and 0 deletions

53
internal/util_test.go Normal file
View File

@ -0,0 +1,53 @@
package internal
import (
"strings"
"testing"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)
func BenchmarkToLowerStd(b *testing.B) {
str := "AaBbCcDdEeFfGgHhIiJjKk"
for i := 0; i < b.N; i++ {
_ = strings.ToLower(str)
}
}
// util.ToLower is 3x faster than strings.ToLower.
func BenchmarkToLowerInternal(b *testing.B) {
str := "AaBbCcDdEeFfGgHhIiJjKk"
for i := 0; i < b.N; i++ {
_ = ToLower(str)
}
}
func TestToLower(t *testing.T) {
It("toLower", func() {
str := "AaBbCcDdEeFfGg"
Expect(ToLower(str)).To(Equal(strings.ToLower(str)))
str = "ABCDE"
Expect(ToLower(str)).To(Equal(strings.ToLower(str)))
str = "ABCDE"
Expect(ToLower(str)).To(Equal(strings.ToLower(str)))
str = "abced"
Expect(ToLower(str)).To(Equal(strings.ToLower(str)))
})
}
func TestIsLower(t *testing.T) {
It("isLower", func() {
str := "AaBbCcDdEeFfGg"
Expect(isLower(str)).To(BeFalse())
str = "ABCDE"
Expect(isLower(str)).To(BeFalse())
str = "abcdefg"
Expect(isLower(str)).To(BeTrue())
})
}