BurntSushi / quickcheck

Automated property based testing for Rust (with shrinking).
The Unlicense
2.4k stars 149 forks source link

Implement Arbitrary for CString #165

Closed clarfonthey closed 3 years ago

clarfonthey commented 7 years ago

Would be nice to have. String's impl isn't quite the same.

BurntSushi commented 4 years ago

PR's are welcome for this.

ThomasdenH commented 4 years ago

What would be the ideal implementation here? Using the String implementation with a null-character or random non-null bytes terminated by a null character? Or some combination of the two?

For example, based on a random variable, either add a valid UTF-8 character to the string or a random non-null byte. Finally, end the string with '\0'.

BurntSushi commented 4 years ago

Yeah, I think we probably want a mix. I believe the Arbitrary impl for String has some smarts to it, and it would be nice to reuse that. While perhaps not optimal, I think one possible implementation of this would be: