BurntSushi / quickcheck

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

Implement Arbitrary for `std::fmt::Formatter` #253

Closed maxbla closed 4 years ago

maxbla commented 4 years ago

This could be helpful for users implementing formatting traits on types defined in their crate.

I'm not sure if this will be easy, as "Users do not construct Formatters directly; a mutable reference to one is passed to the fmt method of all formatting traits" (docs) I would be happy to submit a PR for this, but I generally gauge support first.

BurntSushi commented 4 years ago

Could yoy elaborate a bit on the kinds of properties you would test with this?

Also, could you say how you see such an impl existing? If you can't construct a value then I don't think there's much you can do...

maxbla commented 4 years ago

You might test that Displaying some number type always has 10 digits after the . when the precision of Formatter is 10.

Now that I'm writing it down, this doesn't make a whole lot of sense. The test would fail if width were large and align was Alignment::Left

maxbla commented 4 years ago

A more obvious property is that formatting should be deterministic i.e. for every Formatter and user defined type, formatting twice should give the same result.

BurntSushi commented 4 years ago

I'm not really sure how useful this is. And as I mentioned, given that one cannot construct a value of this type, I don't see how to fulfill this request. Feel free to re-open if you see a way to do this.