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

Output multi-line string literals inside nested objects.

Open coolbluewater opened this issue 11 months ago • 3 comments

Asserting on top-level structs that contain a data hierarchy works and is very useful. However, strings are always output as single line strings and I could not find a way to have them output as multi line string literals. It isn't possible to use assert_str_eq because the struct can't easily implement AsRef.

Any guidance on how to do this, or is this a feature request?

coolbluewater avatar Mar 23 '24 10:03 coolbluewater

Agreed this is not currently possible with pretty_assertions. At the moment the Debug representation is used, which for strings is a single line.

I can imagine that this is something that we could implement in the printer layer, but I'm not sure what heuristic you'd want to use for wrapping. You'd also want this to be configurable, and there is open discussion around making the diff output configurable here: https://github.com/rust-pretty-assertions/rust-pretty-assertions/pull/116

tommilligan avatar Mar 24 '24 21:03 tommilligan

@tommilligan, I don't need any wrapping myself, just breaking on newlines is fine. That's also what text editors do by default for raw rust string literals.

coolbluewater avatar Mar 27 '24 10:03 coolbluewater

It might be possible to do this using autoref specialization to specialize on &str and String. Not sure how this would work within nested fields in a struct though.

TehPers avatar Aug 18 '24 06:08 TehPers