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
Conversation
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.
Thanks @CorentinClabaut for this new contribution 🎉
string.go
Outdated
|
||
// RandomString return a random string. | ||
// Play: https://go.dev/play/p/5zFLTHCxe_T | ||
func RandomString[T ~string](size int, charset string) 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.
|
||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can you use is.PanicsWithError("lo.RandomString: Size parameter must be greater than 0", RandomString(...))
please ?
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.
Sure makes sense!
closes #265