New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RandomString #266
Add RandomString #266
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,30 @@ package lo | |
|
||
import ( | ||
"math" | ||
"math/rand" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRandomString(t *testing.T) { | ||
t.Parallel() | ||
is := assert.New(t) | ||
|
||
rand.Seed(time.Now().UnixNano()) | ||
|
||
str1 := RandomString[string](100, LowerCaseLettersCharset) | ||
is.Equal(100, len(str1)) | ||
is.Subset([]byte(LowerCaseLettersCharset), []byte(str1)) | ||
|
||
str2 := RandomString[string](100, LowerCaseLettersCharset) | ||
is.NotEqual(str1, str2) | ||
|
||
is.Panics(func() { RandomString[string](100, "") }) | ||
is.Panics(func() { RandomString[string](0, LowerCaseLettersCharset) }) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add some tests with non utf-8 runes in charset? 🙏 Such as emoji... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, can you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure makes sense! |
||
|
||
func TestChunkString(t *testing.T) { | ||
t.Parallel() | ||
is := assert.New(t) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to return a [T ~string] ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this adds much value indeed.