From f7b15a35484321a8b8cf510e9db2861fbb1666f1 Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Mon, 18 Dec 2023 17:27:27 +0800 Subject: [PATCH] test: add ut for util_test Signed-off-by: rfyiamcool --- internal/util_test.go | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 internal/util_test.go diff --git a/internal/util_test.go b/internal/util_test.go new file mode 100644 index 0000000000..f090ebaa4b --- /dev/null +++ b/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()) + }) +}