Skip to content
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

Merged
merged 2 commits into from Nov 15, 2022
Merged

Add RandomString #266

merged 2 commits into from Nov 15, 2022

Conversation

CorentinClabaut
Copy link
Contributor

closes #265

Copy link
Owner

@samber samber left a 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 {
Copy link
Owner

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] ?

Copy link
Contributor Author

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) })
}
Copy link
Owner

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...

Copy link
Owner

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure makes sense!

@samber samber merged commit a3c90f1 into samber:master Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add function RandomString that generates a random string
2 participants