Skip to content

Commit

Permalink
Because serde-rs/serde#2371 and serde-rs/serde#1904 are fixed, remove…
Browse files Browse the repository at this point in the history
… workarounds for them
  • Loading branch information
Mingun committed Oct 12, 2024
1 parent e93181c commit 5d4a04d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 91 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ arbitrary = { version = "1", features = ["derive"], optional = true }
criterion = "0.4"
pretty_assertions = "1.4"
regex = "1"
# #[serde(other)] allowed not only inside field_identifier since 1.0.79
# https://github.com/serde-rs/serde/issues/1904 is fixed since 1.0.206
# serde does not follow semver in numbering and their dependencies, so we specifying patch here
serde_derive = { version = "1.0.79" }
serde_derive = { version = "1.0.206" }
serde-value = "0.7"
tokio = { version = "1.21", default-features = false, features = ["macros", "rt"] }
tokio-test = "0.4"
Expand Down
131 changes: 42 additions & 89 deletions tests/serde-se.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ enum ExternallyTagged {
nested: Nested,
string: &'static str,
},
Flatten {
#[serde(flatten)]
nested: Nested,
string: &'static str,
},
/// `float` field serialized as textual content instead of a tag
Text {
#[serde(rename = "$text")]
Expand All @@ -80,22 +85,6 @@ enum ExternallyTagged {
},
}

/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
/// incorrect code generation when deriving `Deserialize`.
///
/// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
///
/// Anyway, deserialization of that type in roundtrip suffers from
/// <https://github.com/serde-rs/serde/issues/1183>
#[derive(Debug, PartialEq, Deserialize, Serialize)]
enum ExternallyTaggedWorkaround {
Flatten {
#[serde(flatten)]
nested: Nested,
string: &'static str,
},
}

#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "tag")]
enum InternallyTagged {
Expand All @@ -111,6 +100,11 @@ enum InternallyTagged {
nested: Nested,
string: &'static str,
},
Flatten {
#[serde(flatten)]
nested: Nested,
string: &'static str,
},
/// `float` field serialized as textual content instead of a tag
Text {
#[serde(rename = "$text")]
Expand All @@ -124,23 +118,6 @@ enum InternallyTagged {
},
}

/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
/// incorrect code generation when deriving `Deserialize`.
///
/// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
///
/// Anyway, deserialization of that type in roundtrip suffers from
/// <https://github.com/serde-rs/serde/issues/1183>
#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "tag")]
enum InternallyTaggedWorkaround {
Flatten {
#[serde(flatten)]
nested: Nested,
string: &'static str,
},
}

#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "tag", content = "content")]
enum AdjacentlyTagged {
Expand All @@ -155,6 +132,11 @@ enum AdjacentlyTagged {
nested: Nested,
string: &'static str,
},
Flatten {
#[serde(flatten)]
nested: Nested,
string: &'static str,
},
/// `float` field serialized as textual content instead of a tag
Text {
#[serde(rename = "$text")]
Expand All @@ -168,23 +150,6 @@ enum AdjacentlyTagged {
},
}

/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
/// incorrect code generation when deriving `Deserialize`.
///
/// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
///
/// Anyway, deserialization of that type in roundtrip suffers from
/// <https://github.com/serde-rs/serde/issues/1183>
#[derive(Serialize)]
#[serde(tag = "tag", content = "content")]
enum AdjacentlyTaggedWorkaround {
Flatten {
#[serde(flatten)]
nested: Nested,
string: &'static str,
},
}

#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(untagged)]
enum Untagged {
Expand All @@ -199,6 +164,11 @@ enum Untagged {
nested: Nested,
string: &'static str,
},
Flatten {
#[serde(flatten)]
nested: Nested,
string: &'static str,
},
/// `float` field serialized as textual content instead of a tag
Text {
#[serde(rename = "$text")]
Expand All @@ -212,23 +182,6 @@ enum Untagged {
},
}

/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
/// incorrect code generation when deriving `Deserialize`.
///
/// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
///
/// Anyway, deserialization of that type in roundtrip suffers from
/// <https://github.com/serde-rs/serde/issues/1183>
#[derive(Serialize)]
#[serde(untagged)]
enum UntaggedWorkaround {
Flatten {
#[serde(flatten)]
nested: Nested,
string: &'static str,
},
}

mod without_root {
use super::*;
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -443,7 +396,7 @@ mod without_root {
// NOTE: Cannot be deserialized in roundtrip due to
// https://github.com/serde-rs/serde/issues/1183
serialize_as_only!(flatten_struct:
ExternallyTaggedWorkaround::Flatten {
ExternallyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
Expand Down Expand Up @@ -822,7 +775,7 @@ mod without_root {
// NOTE: Cannot be deserialized in roundtrip due to
// https://github.com/serde-rs/serde/issues/1183
serialize_as_only!(flatten_struct:
Root { field: ExternallyTaggedWorkaround::Flatten {
Root { field: ExternallyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}}
Expand Down Expand Up @@ -914,7 +867,7 @@ mod without_root {
// NOTE: Cannot be deserialized in roundtrip due to
// https://github.com/serde-rs/serde/issues/1183
serialize_as_only!(flatten_struct:
Root { field: Inner { inner: ExternallyTaggedWorkaround::Flatten {
Root { field: Inner { inner: ExternallyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}}}
Expand Down Expand Up @@ -996,12 +949,12 @@ mod without_root {
=> Unsupported("cannot serialize enum struct variant `ExternallyTagged::Holder` as text content value"),
"<Root");
err!(flatten_struct:
Root { field: ExternallyTaggedWorkaround::Flatten {
Root { field: ExternallyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}}
// Flatten enum struct variants represented as newtype variants containing maps
=> Unsupported("cannot serialize enum newtype variant `ExternallyTaggedWorkaround::Flatten` as text content value"),
=> Unsupported("cannot serialize enum newtype variant `ExternallyTagged::Flatten` as text content value"),
"<Root");
err!(empty_struct:
Root { field: ExternallyTagged::Empty {} }
Expand Down Expand Up @@ -1055,12 +1008,12 @@ mod without_root {
=> Unsupported("cannot serialize enum struct variant `ExternallyTagged::Holder` as text content value"),
"<Root");
err!(flatten_struct:
Root { field: Inner { inner: ExternallyTaggedWorkaround::Flatten {
Root { field: Inner { inner: ExternallyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}}}
// Flatten enum struct variants represented as newtype variants containing maps
=> Unsupported("cannot serialize enum newtype variant `ExternallyTaggedWorkaround::Flatten` as text content value"),
=> Unsupported("cannot serialize enum newtype variant `ExternallyTagged::Flatten` as text content value"),
"<Root");
err!(empty_struct:
Root { field: Inner { inner: ExternallyTagged::Empty {} } }
Expand Down Expand Up @@ -1125,7 +1078,7 @@ mod without_root {
// serde serializes flatten structs as maps, and we do not support
// serialization of maps without root tag
err!(flatten_struct:
InternallyTaggedWorkaround::Flatten {
InternallyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
Expand Down Expand Up @@ -1201,17 +1154,17 @@ mod without_root {
// NOTE: Cannot be deserialized in roundtrip due to
// https://github.com/serde-rs/serde/issues/1183
serialize_as_only!(flatten_struct:
AdjacentlyTaggedWorkaround::Flatten {
AdjacentlyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
=> "<AdjacentlyTaggedWorkaround>\
=> "<AdjacentlyTagged>\
<tag>Flatten</tag>\
<content>\
<float>42</float>\
<string>answer</string>\
</content>\
</AdjacentlyTaggedWorkaround>");
</AdjacentlyTagged>");
serialize_as!(empty_struct:
AdjacentlyTagged::Empty {}
=> "<AdjacentlyTagged>\
Expand Down Expand Up @@ -1272,7 +1225,7 @@ mod without_root {
// serde serializes flatten structs as maps, and we do not support
// serialization of maps without root tag
err!(flatten_struct:
UntaggedWorkaround::Flatten {
Untagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
Expand Down Expand Up @@ -1470,7 +1423,7 @@ mod without_root {
<string>answer</string>\n\
</Holder>");
serialize_as!(flatten_struct:
ExternallyTaggedWorkaround::Flatten {
ExternallyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
Expand Down Expand Up @@ -1575,7 +1528,7 @@ mod without_root {
// serde serializes flatten structs as maps, and we do not support
// serialization of maps without root tag
err!(flatten_struct:
InternallyTaggedWorkaround::Flatten {
InternallyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
Expand Down Expand Up @@ -1647,17 +1600,17 @@ mod without_root {
</content>\n\
</AdjacentlyTagged>");
serialize_as!(flatten_struct:
AdjacentlyTaggedWorkaround::Flatten {
AdjacentlyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
=> "<AdjacentlyTaggedWorkaround>\n \
=> "<AdjacentlyTagged>\n \
<tag>Flatten</tag>\n \
<content>\n \
<float>42</float>\n \
<string>answer</string>\n \
</content>\n\
</AdjacentlyTaggedWorkaround>");
</AdjacentlyTagged>");
serialize_as!(empty_struct:
AdjacentlyTagged::Empty {}
=> "<AdjacentlyTagged>\n \
Expand Down Expand Up @@ -1710,7 +1663,7 @@ mod without_root {
<string>answer</string>\n\
</Untagged>");
err!(flatten_struct:
UntaggedWorkaround::Flatten {
Untagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
Expand Down Expand Up @@ -2053,7 +2006,7 @@ mod with_root {
// NOTE: Cannot be deserialized in roundtrip due to
// https://github.com/serde-rs/serde/issues/1183
serialize_as_only!(flatten_struct:
ExternallyTaggedWorkaround::Flatten {
ExternallyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
Expand Down Expand Up @@ -2167,7 +2120,7 @@ mod with_root {
// NOTE: Cannot be deserialized in roundtrip due to
// https://github.com/serde-rs/serde/issues/1183
serialize_as_only!(flatten_struct:
InternallyTaggedWorkaround::Flatten {
InternallyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
Expand Down Expand Up @@ -2247,7 +2200,7 @@ mod with_root {
// NOTE: Cannot be deserialized in roundtrip due to
// https://github.com/serde-rs/serde/issues/1183
serialize_as_only!(flatten_struct:
AdjacentlyTaggedWorkaround::Flatten {
AdjacentlyTagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
Expand Down Expand Up @@ -2326,7 +2279,7 @@ mod with_root {
// NOTE: Cannot be deserialized in roundtrip due to
// https://github.com/serde-rs/serde/issues/1183
serialize_as_only!(flatten_struct:
UntaggedWorkaround::Flatten {
Untagged::Flatten {
nested: Nested { float: 42.0 },
string: "answer",
}
Expand Down

0 comments on commit 5d4a04d

Please sign in to comment.