github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/x/stringsx/util_test.go (about) 1 package stringsx_test 2 3 import ( 4 "strings" 5 "testing" 6 7 . "github.com/onsi/gomega" 8 9 "github.com/machinefi/w3bstream/pkg/depends/x/stringsx" 10 ) 11 12 func TestGenRandomVisibleString(t *testing.T) { 13 var visibleChars []byte 14 for i := byte(0); i < 95; i++ { 15 visibleChars = append(visibleChars, i+32) 16 } 17 t.Log(string(visibleChars)) 18 19 fs := []func(int, ...byte) string{ 20 stringsx.GenRandomVisibleStringV1, 21 stringsx.GenRandomVisibleStringV2, 22 } 23 24 for _, f := range fs { 25 NewWithT(t).Expect(len(f(10))).To(Equal(10)) 26 s := f(20, '_') 27 NewWithT(t).Expect(len(s)).To(Equal(20)) 28 NewWithT(t).Expect(strings.Contains(s, "_")).To(BeFalse()) 29 s = f(100, '_', '\'', ' ') 30 NewWithT(t).Expect(len(s)).To(Equal(100)) 31 NewWithT(t).Expect(strings.Contains(s, "_")).To(BeFalse()) 32 NewWithT(t).Expect(strings.Contains(s, "'")).To(BeFalse()) 33 NewWithT(t).Expect(strings.Contains(s, " ")).To(BeFalse()) 34 } 35 } 36 37 func BenchmarkGenRandomVisibleString(b *testing.B) { 38 for i := 0; i < b.N; i++ { 39 stringsx.GenRandomVisibleStringV1(8) 40 } 41 } 42 43 func BenchmarkGenRandomVisibleStringV2(b *testing.B) { 44 for i := 0; i < b.N; i++ { 45 stringsx.GenRandomVisibleStringV2(8) 46 } 47 }