Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add ut for util_test #2840

Merged
merged 4 commits into from Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions internal/util_test.go
@@ -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())
})
}