use std::borrow::Cow;
use super::ValidationError;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ValidationReport {
pub errors: Vec<ValidationError>,
pub warnings: Vec<ValidationWarning>,
}
impl ValidationReport {
#[must_use]
#[inline]
pub fn is_ok(&self) -> bool {
self.errors.is_empty()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ValidationWarning {
pub message: Cow<'static, str>,
}
impl ValidationWarning {
#[must_use]
#[inline]
pub fn message(&self) -> &str {
&self.message
}
}
#[inline]
pub(crate) fn warn(message: impl Into<Cow<'static, str>>) -> ValidationWarning {
ValidationWarning {
message: message.into(),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_report_is_ok() {
let report = ValidationReport::default();
assert!(report.is_ok());
}
#[test]
fn report_with_error_is_not_ok() {
let mut report = ValidationReport::default();
report.errors.push(ValidationError {
message: Cow::Borrowed("test error"),
});
assert!(!report.is_ok());
}
#[test]
fn warn_builds_warning() {
let w = warn("narrowing cast");
assert_eq!(w.message(), "narrowing cast");
}
#[test]
fn warning_clone_and_eq() {
let a = warn("test");
let b = a.clone();
assert_eq!(a, b);
}
#[test]
fn report_clone_and_eq() {
let a = ValidationReport::default();
let b = a.clone();
assert_eq!(a, b);
}
}