Issue 3: fixed unevaluating of empty complex items
This commit is contained in:
+8
-1
@@ -16,7 +16,7 @@ pub struct Uneval<W: Write> {
|
||||
}
|
||||
|
||||
impl<W: Write> Uneval<W> {
|
||||
pub(crate) fn new(target: W) -> Self {
|
||||
pub fn new(target: W) -> Self {
|
||||
Self {
|
||||
writer: target,
|
||||
inside: false,
|
||||
@@ -267,6 +267,7 @@ impl<W: Write> ser::SerializeSeq for &mut Uneval<W> {
|
||||
|
||||
fn end(self) -> SerResult {
|
||||
write!(self.writer, "].into_iter().collect()")?;
|
||||
self.inside = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -283,6 +284,7 @@ impl<W: Write> ser::SerializeTuple for &mut Uneval<W> {
|
||||
|
||||
fn end(self) -> SerResult {
|
||||
write!(self.writer, ")) }}")?;
|
||||
self.inside = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -299,6 +301,7 @@ impl<W: Write> ser::SerializeTupleStruct for &mut Uneval<W> {
|
||||
|
||||
fn end(self) -> SerResult {
|
||||
write!(self.writer, ")")?;
|
||||
self.inside = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -315,6 +318,7 @@ impl<W: Write> ser::SerializeTupleVariant for &mut Uneval<W> {
|
||||
|
||||
fn end(self) -> SerResult {
|
||||
write!(self.writer, ")")?;
|
||||
self.inside = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -344,6 +348,7 @@ impl<W: Write> ser::SerializeMap for &mut Uneval<W> {
|
||||
|
||||
fn end(self) -> SerResult {
|
||||
write!(self.writer, "].into_iter().collect()")?;
|
||||
self.inside = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -367,6 +372,7 @@ impl<W: Write> ser::SerializeStruct for &mut Uneval<W> {
|
||||
|
||||
fn end(self) -> SerResult {
|
||||
write!(self.writer, "}}")?;
|
||||
self.inside = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -390,6 +396,7 @@ impl<W: Write> ser::SerializeStructVariant for &mut Uneval<W> {
|
||||
|
||||
fn end(self) -> SerResult {
|
||||
write!(self.writer, "}}")?;
|
||||
self.inside = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
+44
-2
@@ -93,6 +93,8 @@ pub enum Enum {
|
||||
Unit(Unit),
|
||||
Tuple(i32, String),
|
||||
Struct{ key: i32, value: String },
|
||||
EmptyTuple(),
|
||||
EmptyStruct {},
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Serialize)]
|
||||
@@ -102,10 +104,13 @@ value = """
|
||||
{
|
||||
use definition::*;
|
||||
Container(vec![
|
||||
Enum::Empty,
|
||||
Enum::Unit(Unit),
|
||||
Enum::Tuple(1, "test".into()),
|
||||
Enum::Struct{ key: 1, value: "test".into() },
|
||||
Enum::EmptyTuple(),
|
||||
Enum::EmptyStruct{},
|
||||
// this is intentionally last, to catch an error at previous step
|
||||
Enum::Empty,
|
||||
])
|
||||
}
|
||||
"""
|
||||
@@ -128,4 +133,41 @@ pub struct ZeroSizeContainer(pub [u8; 0]);
|
||||
"""
|
||||
value = """
|
||||
definition::ZeroSizeContainer([])
|
||||
"""
|
||||
"""
|
||||
|
||||
[empty_fields_issue_3]
|
||||
main_type = "Foo"
|
||||
support_types = "UnitType,UnitStruct,UnitTuple"
|
||||
definition = """
|
||||
use std::collections::HashMap;
|
||||
#[derive(PartialEq, Debug, Serialize)]
|
||||
pub struct UnitType;
|
||||
#[derive(PartialEq, Debug, Serialize)]
|
||||
pub struct UnitStruct {}
|
||||
#[derive(PartialEq, Debug, Serialize)]
|
||||
pub struct UnitTuple();
|
||||
#[derive(PartialEq, Debug, Serialize)]
|
||||
pub struct Foo {
|
||||
pub vec: Vec<String>,
|
||||
pub map: HashMap<String, String>,
|
||||
pub unit: (),
|
||||
pub unit_type: UnitType,
|
||||
pub unit_struct: UnitStruct,
|
||||
pub unit_tuple: UnitTuple,
|
||||
pub last: String
|
||||
}
|
||||
"""
|
||||
value = """
|
||||
{
|
||||
use definition::*;
|
||||
Foo {
|
||||
vec: vec![],
|
||||
map: std::collections::HashMap::new(),
|
||||
unit: (),
|
||||
unit_type: UnitType,
|
||||
unit_struct: UnitStruct {},
|
||||
unit_tuple: UnitTuple(),
|
||||
last: "".into()
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user