Skip to content

Commit

Permalink
Add serialize double
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Sep 19, 2023
1 parent 67ae7e6 commit 9d3c382
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions crates/serde-firestore-value/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ mod tests {
}

fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> {
todo!()
self.serialize_f64(f64::from(v))
}

fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error> {
todo!()
self.output.value_type = Some(ValueType::DoubleValue(v));
Ok(())
}

fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error> {
Expand Down Expand Up @@ -414,4 +415,38 @@ mod tests {
);
Ok(())
}

#[test]
fn test_f32() -> anyhow::Result<()> {
assert_eq!(
to_value(&f32::MAX)?,
Value {
value_type: Some(ValueType::DoubleValue(f64::from(f32::MAX)))
}
);
assert_eq!(
to_value(&f32::MIN)?,
Value {
value_type: Some(ValueType::DoubleValue(f64::from(f32::MIN)))
}
);
Ok(())
}

#[test]
fn test_f64() -> anyhow::Result<()> {
assert_eq!(
to_value(&f64::MAX)?,
Value {
value_type: Some(ValueType::DoubleValue(f64::MAX))
}
);
assert_eq!(
to_value(&f64::MIN)?,
Value {
value_type: Some(ValueType::DoubleValue(f64::MIN))
}
);
Ok(())
}
}

0 comments on commit 9d3c382

Please sign in to comment.