use serde::{Deserialize, Serialize};
pub use crate::excel_error::ExcelError;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, schemars::JsonSchema)]
pub enum CellValue {
Number(f64),
Text(String),
Bool(bool),
Empty,
Error(ExcelError),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn number_serializes_to_its_value() {
assert_eq!(
serde_json::to_value(CellValue::Number(238.728)).unwrap()["Number"],
238.728
);
}
#[test]
fn text_serializes() {
assert_eq!(
serde_json::to_value(CellValue::Text("hi".to_string())).unwrap()["Text"],
"hi"
);
}
#[test]
fn bool_serializes() {
assert_eq!(
serde_json::to_value(CellValue::Bool(true)).unwrap()["Bool"],
true
);
}
#[test]
fn empty_serializes_to_tag() {
assert_eq!(serde_json::to_value(CellValue::Empty).unwrap(), "Empty");
}
#[test]
fn error_serializes_re_exported_excel_error() {
let v = serde_json::to_value(CellValue::Error(ExcelError::DivZero)).unwrap();
assert_eq!(v["Error"], "DivZero");
}
}