Skip to main content

Crate assert_str

Crate assert_str 

Source
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!.

MacrosNormalization 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(&str or String) are identical. It ignores different new line characters for different OSes: \n or \r\n.
assert_str_ne
Asserts that multiline strings(&str or String) are not identical. It ignores different new line characters for different OSes: \n or \r\n.
assert_str_trim_all_eq
Asserts that multiline strings(&str or String) 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(&str or String) 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(&str or String) are identical when every line is trimmed and empty lines are removed. It ignores different new line characters for different OSes: \n or \r\n.
assert_str_trim_ne
Asserts that multiline strings(&str or String) are not identical when every line is trimmed and empty lines are removed. It ignores different new line characters for different OSes: \n or \r\n.

Enums§

Mode
Normalization strategy shared by all of the assertion macros.

Functions§

normalize
Normalizes s according to mode, returning the canonical form that the assertion macros compare.