rust-pretty-assertions icon indicating copy to clipboard operation
rust-pretty-assertions copied to clipboard

Hex/Binary diff and formatting for number collections

Open XAMPPRocky opened this issue 2 years ago • 3 comments

Hello, I really like using this crate for my tests as it makes it a lot easier to spot which byte has changed or regressed from a change. It would be nice if the crate supported hex and/or binary formatting for collections of numbers (e.g. &[u8]), so that you could see much more easily on the bit level what changed about a number, as currently see the difference between two base-10 numbers isn't that useful for me when comparing binary serialisation output.

XAMPPRocky avatar Feb 25 '23 01:02 XAMPPRocky

Hey, thanks for your feedback. Custom formatting is a widely requested feature - it's good to have the additional data points of binary/hex output format.

I have some ideas on how this could be supported with an opt-in feature, I will keep you posted if I implement them.

tommilligan avatar Mar 15 '23 22:03 tommilligan

FWIW since it is a macro, you could always add an additional argument to the macro that accepts a Settings type, this would keep it being compatible with std::assert_* but allow people to opt in on a case by case basis, as at least right now I don't think I would want it to be something that's crate wide enabled or disabled.

assert_eq!([0x80, 0x70], [0x70, 0x80], "binary output mismatched", pretty_assertions::Settings::hex());

XAMPPRocky avatar Mar 16 '23 10:03 XAMPPRocky

@tommilligan I'm also interested in this feature. How much more discussion / design do you think is needed? Do you think you might be open to a PR at some point?

xpe avatar Sep 07 '23 17:09 xpe