Skip to content

Commit

Permalink
test: add ut for util_test
Browse files Browse the repository at this point in the history
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
  • Loading branch information
rfyiamcool committed Dec 19, 2023
1 parent 73c879d commit 6333c4a
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions internal/util_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
}

0 comments on commit 6333c4a

Please sign in to comment.