github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/internal/util/to_lower_test.go (about)

     1  package util
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestToLower(t *testing.T) {
     9  	strs := []string{
    10  		"aaaa_bbbb-cccc",
    11  		"aaaA_Bbbb-CCCC",
    12  		"AAAA_BBBB-cccc",
    13  	}
    14  	for _, str := range strs {
    15  		dst1 := ToLower(str)
    16  		dst2 := strings.ToLower(str)
    17  		if dst1 != dst2 {
    18  			t.Errorf("TestToLower failed, have: %s, want %s\n", dst1, dst2)
    19  		}
    20  	}
    21  }
    22  
    23  func BenchmarkToLower(b *testing.B) {
    24  	s := "scancode_waitmsg"
    25  	b.ReportAllocs()
    26  	b.ResetTimer()
    27  	for i := 0; i < b.N; i++ {
    28  		ToLower(s)
    29  	}
    30  }
    31  
    32  func BenchmarkStringsToLower(b *testing.B) {
    33  	s := "scancode_waitmsg"
    34  	b.ReportAllocs()
    35  	b.ResetTimer()
    36  	for i := 0; i < b.N; i++ {
    37  		strings.ToLower(s)
    38  	}
    39  }