github.com/neohugo/neohugo@v0.123.8/common/hstrings/strings_test.go (about) 1 // Copyright 2024 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package hstrings 15 16 import ( 17 "regexp" 18 "testing" 19 20 qt "github.com/frankban/quicktest" 21 ) 22 23 func TestStringEqualFold(t *testing.T) { 24 c := qt.New(t) 25 26 s1 := "A" 27 s2 := "a" 28 29 c.Assert(StringEqualFold(s1).EqualFold(s2), qt.Equals, true) 30 c.Assert(StringEqualFold(s1).EqualFold(s1), qt.Equals, true) 31 c.Assert(StringEqualFold(s2).EqualFold(s1), qt.Equals, true) 32 c.Assert(StringEqualFold(s2).EqualFold(s2), qt.Equals, true) 33 c.Assert(StringEqualFold(s1).EqualFold("b"), qt.Equals, false) 34 c.Assert(StringEqualFold(s1).Eq(s2), qt.Equals, true) 35 c.Assert(StringEqualFold(s1).Eq("b"), qt.Equals, false) 36 } 37 38 func TestGetOrCompileRegexp(t *testing.T) { 39 c := qt.New(t) 40 41 re, err := GetOrCompileRegexp(`\d+`) 42 c.Assert(err, qt.IsNil) 43 c.Assert(re.MatchString("123"), qt.Equals, true) 44 } 45 46 func BenchmarkGetOrCompileRegexp(b *testing.B) { 47 for i := 0; i < b.N; i++ { 48 // nolint 49 GetOrCompileRegexp(`\d+`) 50 } 51 } 52 53 func BenchmarkCompileRegexp(b *testing.B) { 54 for i := 0; i < b.N; i++ { 55 regexp.MustCompile(`\d+`) 56 } 57 }