Address feedback on PR #905

* Added error test when deny_unknown_fields enabled
* Fixed next_relevant_key to use absolute paths
This commit is contained in:
Ted Driggs 2017-04-27 12:21:32 -07:00
parent 873cfbe9ab
commit 2440b59aae
2 changed files with 63 additions and 3 deletions

View File

@ -866,7 +866,7 @@ fn deserialize_adjacently_tagged_enum(
} else {
quote! {
{
let mut __rk : Option<_serde::private::de::TagOrContentField> = None;
let mut __rk : _serde::export::Option<_serde::private::de::TagOrContentField> = _serde::export::None;
while let _serde::export::Some(__k) = #next_key {
match __k {
_serde::private::de::TagContentOtherField::Other => {
@ -874,11 +874,11 @@ fn deserialize_adjacently_tagged_enum(
continue;
},
_serde::private::de::TagContentOtherField::Tag => {
__rk = Some(_serde::private::de::TagOrContentField::Tag);
__rk = _serde::export::Some(_serde::private::de::TagOrContentField::Tag);
break;
}
_serde::private::de::TagContentOtherField::Content => {
__rk = Some(_serde::private::de::TagOrContentField::Content);
__rk = _serde::export::Some(_serde::private::de::TagOrContentField::Content);
break;
}
}

View File

@ -885,6 +885,66 @@ fn test_adjacently_tagged_enum() {
);
}
#[test]
fn test_adjacently_tagged_enum_deny_unknown_fields() {
#[derive(Debug, PartialEq, Deserialize)]
#[serde(tag = "t", content = "c", deny_unknown_fields)]
enum AdjacentlyTagged {
Unit,
}
assert_de_tokens(
&AdjacentlyTagged::Unit,
&[
Token::Struct { name: "AdjacentlyTagged", len: 2},
Token::Str("t"),
Token::Str("Unit"),
Token::Str("c"),
Token::Unit,
Token::StructEnd,
],
);
assert_de_tokens_error::<AdjacentlyTagged>(
&[
Token::Struct { name: "AdjacentlyTagged", len: 3},
Token::Str("t"),
Token::Str("Unit"),
Token::Str("c"),
Token::Unit,
Token::Str("h"),
],
r#"invalid value: string "h", expected "t" or "c""#
);
assert_de_tokens_error::<AdjacentlyTagged>(
&[
Token::Struct { name: "AdjacentlyTagged", len: 3},
Token::Str("h"),
],
r#"invalid value: string "h", expected "t" or "c""#
);
assert_de_tokens_error::<AdjacentlyTagged>(
&[
Token::Struct { name: "AdjacentlyTagged", len: 3},
Token::Str("c"),
Token::Unit,
Token::Str("h"),
],
r#"invalid value: string "h", expected "t" or "c""#
);
}
#[test]
fn test_enum_in_internally_tagged_enum() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]