Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions validator/src/display_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::{ValidationError, ValidationErrors, ValidationErrorsKind};
impl fmt::Display for ValidationError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(msg) = self.message.as_ref() {
write!(fmt, "{}", msg)
writeln!(fmt, "{}", msg)
} else {
write!(fmt, "Validation error: {} [{:?}]", self.code, self.params)
writeln!(fmt, "Validation error: {} [{:?}]", self.code, self.params)
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions validator/tests/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ mod tests {

#[test]
fn test_nested_vec() {
let bad_foo = Foo { foo: "hi!".into() };
let bad_baz = Baz { baz: vec![bad_foo] };
let bad_foo_1 = Foo { foo: "hi!".into() };
let bad_foo_2 = Foo { foo: "hi!".into() };
let bad_baz = Baz { baz: vec![bad_foo_1, bad_foo_2] };
let err = format!("{}", bad_baz.validate().unwrap_err());
assert_eq!(err, "baz[0].foo: Please provide a valid foo!");
assert_eq!(
err,
"baz[0].foo: Please provide a valid foo!\nbaz[1].foo: Please provide a valid foo!"
);
}
}