rust-pretty-assertions
rust-pretty-assertions copied to clipboard
Output multi-line string literals inside nested objects.
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?
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, 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.
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.