From 4b2354597d17ae2552bf95099b8170193e80c9c1 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 4 Mar 2015 06:57:19 -0800 Subject: [PATCH] Start fixing the json tests --- serde2/src/json/value.rs | 22 ++++++++++++++++------ serde2/tests/test_json.rs | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/serde2/src/json/value.rs b/serde2/src/json/value.rs index 73bbeff8..803f3d41 100644 --- a/serde2/src/json/value.rs +++ b/serde2/src/json/value.rs @@ -104,12 +104,6 @@ impl ser::Visitor for Serializer { type Value = (); type Error = (); - #[inline] - fn visit_unit(&mut self) -> Result<(), ()> { - self.state.push(State::Value(Value::Null)); - Ok(()) - } - #[inline] fn visit_bool(&mut self, value: bool) -> Result<(), ()> { self.state.push(State::Value(Value::Bool(value))); @@ -158,6 +152,22 @@ impl ser::Visitor for Serializer { value.visit(self) } + #[inline] + fn visit_unit(&mut self) -> Result<(), ()> { + self.state.push(State::Value(Value::Null)); + Ok(()) + } + + #[inline] + fn visit_enum_unit(&mut self, _name: &str, variant: &str) -> Result<(), ()> { + let mut values = BTreeMap::new(); + values.insert(variant.to_string(), Value::Array(vec![])); + + self.state.push(State::Value(Value::Object(values))); + + Ok(()) + } + #[inline] fn visit_seq(&mut self, mut visitor: V) -> Result<(), ()> where V: ser::SeqVisitor, diff --git a/serde2/tests/test_json.rs b/serde2/tests/test_json.rs index 27dd2b25..8b759279 100644 --- a/serde2/tests/test_json.rs +++ b/serde2/tests/test_json.rs @@ -346,7 +346,6 @@ fn test_write_tuple() { */ } -/* #[test] fn test_write_enum() { test_encode_ok(&[ @@ -408,6 +407,7 @@ fn test_write_enum() { */ } +/* #[test] fn test_write_option() { test_encode_ok(&[