@@ -25,6 +25,18 @@ func Benchmark_ToUpper(b *testing.B) {
2525 }
2626 AssertEqual (b , "/REPOS/GOFIBER/FIBER/ISSUES/187643/COMMENTS" , res )
2727 })
28+ b .Run ("IfToUpper-Upper" , func (b * testing.B ) {
29+ for n := 0 ; n < b .N ; n ++ {
30+ res = IfToUpper ("/REPOS/GOFIBER/FIBER/ISSUES/187643/COMMENTS" )
31+ }
32+ AssertEqual (b , "/REPOS/GOFIBER/FIBER/ISSUES/187643/COMMENTS" , res )
33+ })
34+ b .Run ("IfToUpper-Mixed" , func (b * testing.B ) {
35+ for n := 0 ; n < b .N ; n ++ {
36+ res = IfToUpper (path )
37+ }
38+ AssertEqual (b , "/REPOS/GOFIBER/FIBER/ISSUES/187643/COMMENTS" , res )
39+ })
2840 b .Run ("default" , func (b * testing.B ) {
2941 for n := 0 ; n < b .N ; n ++ {
3042 res = strings .ToUpper (path )
@@ -56,6 +68,18 @@ func Benchmark_ToLower(b *testing.B) {
5668 }
5769 AssertEqual (b , "/repos/gofiber/fiber/issues/187643/comments" , res )
5870 })
71+ b .Run ("IfToLower-Lower" , func (b * testing.B ) {
72+ for n := 0 ; n < b .N ; n ++ {
73+ res = IfToLower ("/repos/gofiber/fiber/issues/187643/comments" )
74+ }
75+ AssertEqual (b , "/repos/gofiber/fiber/issues/187643/comments" , res )
76+ })
77+ b .Run ("IfToLower-Mixed" , func (b * testing.B ) {
78+ for n := 0 ; n < b .N ; n ++ {
79+ res = IfToLower (path )
80+ }
81+ AssertEqual (b , "/repos/gofiber/fiber/issues/187643/comments" , res )
82+ })
5983 b .Run ("default" , func (b * testing.B ) {
6084 for n := 0 ; n < b .N ; n ++ {
6185 res = strings .ToLower (path )
@@ -147,3 +171,42 @@ func Benchmark_Trim(b *testing.B) {
147171 AssertEqual (b , "foobar" , res )
148172 })
149173}
174+
175+ func Test_IfToUpper (t * testing.T ) {
176+ t .Parallel ()
177+ AssertEqual (t , "MYNAMEISPARAM" , IfToUpper ("MYNAMEISPARAM" )) // already uppercase
178+ AssertEqual (t , "MYNAMEISPARAM" , IfToUpper ("mynameisparam" )) // lowercase to uppercase
179+ AssertEqual (t , "MYNAMEISPARAM" , IfToUpper ("MyNameIsParam" )) // mixed case
180+ }
181+
182+ func Test_IfToLower (t * testing.T ) {
183+ t .Parallel ()
184+ AssertEqual (t , "mynameisparam" , IfToLower ("mynameisparam" )) // already lowercase
185+ AssertEqual (t , "mynameisparam" , IfToLower ("myNameIsParam" )) // mixed case
186+ AssertEqual (t , "https://gofiber.io" , IfToLower ("https://gofiber.io" )) // Origin Header Type URL
187+ AssertEqual (t , "mynameisparam" , IfToLower ("MYNAMEISPARAM" )) // uppercase to lowercase
188+ }
189+
190+ // Benchmark_IfToLower_HeadersOrigin benchmarks the IfToLower function with an origin header type URL.
191+ // These headers are typically lowercase, so the function should return the input string without modification.
192+ func Benchmark_IfToToLower_HeadersOrigin (b * testing.B ) {
193+ var res string
194+ b .Run ("fiber" , func (b * testing.B ) {
195+ for n := 0 ; n < b .N ; n ++ {
196+ res = ToLower ("https://gofiber.io" )
197+ }
198+ AssertEqual (b , "https://gofiber.io" , res )
199+ })
200+ b .Run ("IfToLower-Lower" , func (b * testing.B ) {
201+ for n := 0 ; n < b .N ; n ++ {
202+ res = IfToLower ("https://gofiber.io" )
203+ }
204+ AssertEqual (b , "https://gofiber.io" , res )
205+ })
206+ b .Run ("default" , func (b * testing.B ) {
207+ for n := 0 ; n < b .N ; n ++ {
208+ res = strings .ToLower ("https://gofiber.io" )
209+ }
210+ AssertEqual (b , "https://gofiber.io" , res )
211+ })
212+ }
0 commit comments