Expand description
Macros for asserting multiline String and &str values.
The API mirrors the standard library’s assert_eq! / assert_ne!, but
before comparing, both operands are normalized so that differences which are
usually noise get ignored. Every macro treats \n and \r\n as equivalent;
the trim and trim_all variants additionally normalize whitespace. The
left and right operands may be different types (&str, String,
&String, …).
§Macros
Each *_eq! asserts equality and each *_ne! asserts inequality after
applying the normalization below. All accept an optional trailing format
message, like assert_eq!.
| Macros | Normalization applied before comparing |
|---|---|
assert_str_eq! / assert_str_ne! | Line endings only (\n ≡ \r\n). |
assert_str_trim_eq! / assert_str_trim_ne! | Line endings, plus each line trimmed and blank lines dropped. |
assert_str_trim_all_eq! / assert_str_trim_all_ne! | All whitespace removed, anywhere in the string. |
The same normalization is available directly via normalize and Mode
for reuse outside of assertions.
This crate has no dependencies and contains no unsafe code
(#![forbid(unsafe_code)]).
Macros§
- assert_
str_ eq - Asserts that multiline strings(
&strorString) are identical. It ignores different new line characters for different OSes:\nor\r\n. - assert_
str_ ne - Asserts that multiline strings(
&strorString) are not identical. It ignores different new line characters for different OSes:\nor\r\n. - assert_
str_ trim_ all_ eq - Asserts that multiline strings(
&strorString) are identical after removing all whitespace (spaces, tabs, and line breaks, anywhere in the string). Useful for comparing minified and pretty-printed formats. - assert_
str_ trim_ all_ ne - Asserts that multiline strings(
&strorString) are not identical after removing all whitespace (spaces, tabs, and line breaks, anywhere in the string). Useful for comparing minified and pretty-printed formats. - assert_
str_ trim_ eq - Asserts that multiline strings(
&strorString) are identical when every line is trimmed and empty lines are removed. It ignores different new line characters for different OSes:\nor\r\n. - assert_
str_ trim_ ne - Asserts that multiline strings(
&strorString) are not identical when every line is trimmed and empty lines are removed. It ignores different new line characters for different OSes:\nor\r\n.
Enums§
- Mode
- Normalization strategy shared by all of the assertion macros.
Functions§
- normalize
- Normalizes
saccording tomode, returning the canonical form that the assertion macros compare.