Struct googletest::matcher_support::description::Description
source · pub struct Description { /* private fields */ }
Expand description
Helper structure to build better output of
Matcher::describe
and
Matcher::explain_match
. This
is especially useful with composed matchers and matchers over containers.
It provides simple operations to lazily format lists of strings.
Usage:
let iter: impl Iterator<String> = ...
format!("{}", iter.collect::<Description>().indent().bullet_list())
To construct a Description
, use Iterator<Item=String>::collect()
.
Each element of the collected iterator will be separated by a
newline when displayed. The elements may be multi-line, but they will
nevertheless be indented consistently.
Note that a newline will only be added between each element, but not
after the last element. This makes it simpler to keep
Matcher::describe
and Matcher::explain_match
consistent with simpler Matchers
.
They can also be indented, enumerated and or
bullet listed if Description::indent
, Description::enumerate
, or
respectively Description::bullet_list
has been called.
Implementations§
source§impl Description
impl Description
sourcepub fn indent(self) -> Self
pub fn indent(self) -> Self
Indents the lines in elements of this description.
This operation will be performed lazily when self
is displayed.
This will indent every line inside each element.
For example:
let description = std::iter::once("A B C\nD E F".to_string()).collect::<Description>();
verify_that!(description.indent(), displays_as(eq(" A B C\n D E F")))
sourcepub fn indent_except_first_line(self) -> Self
pub fn indent_except_first_line(self) -> Self
Indents the lines in elements of this description except for the first line.
This is similar to Self::indent
except that the first line is not
indented. This is useful when the first line has already been indented
in the output.
For example:
let description = std::iter::once("A B C\nD E F".to_string()).collect::<Description>();
verify_that!(description.indent_except_first_line(), displays_as(eq("A B C\n D E F")))
sourcepub fn bullet_list(self) -> Self
pub fn bullet_list(self) -> Self
Bullet lists the elements of self
.
This operation will be performed lazily when self
is displayed.
Note that this will only bullet list each element, not each line in each element.
For instance:
let description = std::iter::once("A B C\nD E F".to_string()).collect::<Description>();
verify_that!(description.bullet_list(), displays_as(eq("* A B C\n D E F")))
sourcepub fn enumerate(self) -> Self
pub fn enumerate(self) -> Self
Enumerates the elements of self
.
This operation will be performed lazily when self
is displayed.
Note that this will only enumerate each element, not each line in each element.
For instance:
let description = std::iter::once("A B C\nD E F".to_string()).collect::<Description>();
verify_that!(description.enumerate(), displays_as(eq("0. A B C\n D E F")))