Skip to content

Commit

Permalink
Add serialize none and some
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Sep 19, 2023
1 parent c41b63c commit 536c8b2
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions crates/serde-firestore-value/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ mod tests {
}

fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
todo!()
self.output.value_type = Some(ValueType::NullValue(0));
Ok(())
}

fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: Serialize,
{
todo!()
value.serialize(self)
}

fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
Expand Down Expand Up @@ -481,4 +482,33 @@ mod tests {
);
Ok(())
}

#[test]
fn test_none() -> anyhow::Result<()> {
assert_eq!(
to_value(&None::<Option<i64>>)?,
Value {
value_type: Some(ValueType::NullValue(0_i32))
}
);
Ok(())
}

#[test]
fn test_some() -> anyhow::Result<()> {
// TODO: all types
assert_eq!(
to_value(&Some(true))?,
Value {
value_type: Some(ValueType::BooleanValue(true))
}
);
assert_eq!(
to_value(&Some(1_i64))?,
Value {
value_type: Some(ValueType::IntegerValue(1_i64))
}
);
Ok(())
}
}

0 comments on commit 536c8b2

Please sign in to comment.