Skip to content

Commit

Permalink
feat: Backport IfToLower and IfToUpper functions from v2
Browse files Browse the repository at this point in the history
  • Loading branch information
sixcolors committed Mar 25, 2024
1 parent 5a92a79 commit f0cce84
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func Benchmark_ToUpper(b *testing.B) {
})
b.Run("IfToUpper-Upper", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = IfToUpper(upperStr)
res = IfToUpper("/REPOS/GOFIBER/FIBER/ISSUES/187643/COMMENTS")
}
require.Equal(b, upperStr, res)
AssertEqual(b, "/REPOS/GOFIBER/FIBER/ISSUES/187643/COMMENTS", res)
})
b.Run("IfToUpper-Mixed", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = IfToUpper(largeStr)
res = IfToUpper(path)
}
require.Equal(b, upperStr, res)
AssertEqual(b, "/REPOS/GOFIBER/FIBER/ISSUES/187643/COMMENTS", res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
Expand Down Expand Up @@ -70,15 +70,15 @@ func Benchmark_ToLower(b *testing.B) {
})
b.Run("IfToLower-Lower", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = IfToLower(lowerStr)
res = IfToLower("/repos/gofiber/fiber/issues/187643/comments")
}
require.Equal(b, lowerStr, res)
AssertEqual(b, "/repos/gofiber/fiber/issues/187643/comments", res)
})
b.Run("IfToLower-Mixed", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = IfToLower(largeStr)
res = IfToLower(path)
}
require.Equal(b, lowerStr, res)
AssertEqual(b, "/repos/gofiber/fiber/issues/187643/comments", res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
Expand Down Expand Up @@ -174,17 +174,17 @@ func Benchmark_Trim(b *testing.B) {

func Test_IfToUpper(t *testing.T) {
t.Parallel()
require.Equal(t, "MYNAMEISPARAM", IfToUpper("MYNAMEISPARAM")) // already uppercase
require.Equal(t, "MYNAMEISPARAM", IfToUpper("mynameisparam")) // lowercase to uppercase
require.Equal(t, "MYNAMEISPARAM", IfToUpper("MyNameIsParam")) // mixed case
AssertEqual(t, "MYNAMEISPARAM", IfToUpper("MYNAMEISPARAM")) // already uppercase
AssertEqual(t, "MYNAMEISPARAM", IfToUpper("mynameisparam")) // lowercase to uppercase
AssertEqual(t, "MYNAMEISPARAM", IfToUpper("MyNameIsParam")) // mixed case
}

func Test_IfToLower(t *testing.T) {
t.Parallel()
require.Equal(t, "mynameisparam", IfToLower("mynameisparam")) // already lowercase
require.Equal(t, "mynameisparam", IfToLower("myNameIsParam")) // mixed case
require.Equal(t, "https://gofiber.io", IfToLower("https://gofiber.io")) // Origin Header Type URL
require.Equal(t, "mynameisparam", IfToLower("MYNAMEISPARAM")) // uppercase to lowercase
AssertEqual(t, "mynameisparam", IfToLower("mynameisparam")) // already lowercase
AssertEqual(t, "mynameisparam", IfToLower("myNameIsParam")) // mixed case
AssertEqual(t, "https://gofiber.io", IfToLower("https://gofiber.io")) // Origin Header Type URL
AssertEqual(t, "mynameisparam", IfToLower("MYNAMEISPARAM")) // uppercase to lowercase
}

// Benchmark_IfToLower_HeadersOrigin benchmarks the IfToLower function with an origin header type URL.
Expand All @@ -195,18 +195,18 @@ func Benchmark_IfToToLower_HeadersOrigin(b *testing.B) {
for n := 0; n < b.N; n++ {
res = ToLower("https://gofiber.io")
}
require.Equal(b, "https://gofiber.io", res)
AssertEqual(b, "https://gofiber.io", res)
})
b.Run("IfToLower-Lower", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = IfToLower("https://gofiber.io")
}
require.Equal(b, "https://gofiber.io", res)
AssertEqual(b, "https://gofiber.io", res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = strings.ToLower("https://gofiber.io")
}
require.Equal(b, "https://gofiber.io", res)
AssertEqual(b, "https://gofiber.io", res)
})
}

0 comments on commit f0cce84

Please sign in to comment.