use crate::cell_diff::CellDiff;
use crate::error::{StepError, quote};
use crate::span::Span;
use crate::value::Value;
pub const DOC_STRING_COLUMN: &str = "doc string";
pub fn compare_doc_string(
returned: Option<&Value>,
content: &str,
span: Span,
) -> Result<Option<CellDiff>, StepError> {
let s = match returned {
None => return Ok(None),
Some(Value::String(s)) => s,
Some(other) => {
return Err(StepError::ReturnShape(format!(
"expected a doc string (string), got {}",
other.type_name()
)));
}
};
if s == content {
Ok(None)
} else {
Ok(Some(CellDiff {
column: DOC_STRING_COLUMN.to_string(),
span,
expected: quote(content),
actual: quote(s),
ok: false,
expected_value: None,
actual_value: None,
formatted: false,
}))
}
}