github.com/jxskiss/gopkg@v0.17.3/strutil/random_test.go (about) 1 package strutil 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "math/rand" 6 "testing" 7 ) 8 9 func TestRandPassword(t *testing.T) { 10 for i := 0; i < 10; i++ { 11 length := 3 + rand.Intn(1024) 12 pwd := RandPassword(length) 13 assert.True(t, IsASCII(pwd)) 14 } 15 16 for i := 0; i < 10; i++ { 17 length := 3 + rand.Intn(1024) 18 pwd := RandStrongPassword(length) 19 assert.True(t, IsASCII(pwd)) 20 } 21 } 22 23 func TestRandASCII(t *testing.T) { 24 for i := 0; i < 10; i++ { 25 length := 3 + rand.Intn(1024) 26 letters := RandLetters(length) 27 assert.True(t, IsPrintable(letters)) 28 } 29 30 for i := 0; i < 10; i++ { 31 length := 3 + rand.Intn(1024) 32 lower := RandLowerLetters(length) 33 t.Log("lower:", lower) 34 assert.True(t, IsLower(lower)) 35 } 36 37 for i := 0; i < 10; i++ { 38 length := 3 + rand.Intn(1024) 39 upper := RandUpperLetters(length) 40 assert.True(t, IsUpper(upper)) 41 } 42 43 for i := 0; i < 10; i++ { 44 length := 3 + rand.Intn(1024) 45 digits := RandDigits(length) 46 assert.NotEqual(t, digits[0], '0') 47 assert.True(t, IsASCIIDigit(digits)) 48 assert.True(t, IsDigit(digits)) 49 } 50 51 for i := 0; i < 10; i++ { 52 length := 3 + rand.Intn(1024) 53 str := RandAlphaDigits(length) 54 assert.True(t, IsASCII(str)) 55 assert.True(t, IsPrintable(str)) 56 } 57 }