github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/common/hstrings/strings_test.go (about) 1 // Copyright 2023 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 39 func TestGetOrCompileRegexp(t *testing.T) { 40 c := qt.New(t) 41 42 re, err := GetOrCompileRegexp(`\d+`) 43 c.Assert(err, qt.IsNil) 44 c.Assert(re.MatchString("123"), qt.Equals, true) 45 46 } 47 48 func BenchmarkGetOrCompileRegexp(b *testing.B) { 49 for i := 0; i < b.N; i++ { 50 GetOrCompileRegexp(`\d+`) 51 } 52 } 53 54 func BenchmarkCompileRegexp(b *testing.B) { 55 for i := 0; i < b.N; i++ { 56 regexp.MustCompile(`\d+`) 57 } 58 }