Skip to content

Commit

Permalink
Merge pull request 2560 from Mingun/honest-test
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 3, 2024
2 parents 89139e2 + 6a097ec commit 00c4b0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions serde/src/private/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ mod content {
}
}

/// Used to capture data in [`Content`] from other deserializers.
/// Cannot capture externally tagged enums, `i128` and `u128`.
struct ContentVisitor<'de> {
value: PhantomData<Content<'de>>,
}
Expand Down Expand Up @@ -528,6 +530,8 @@ mod content {
Content(Content<'de>),
}

/// Serves as a seed for deserializing a key of internally tagged enum.
/// Cannot capture externally tagged enums, `i128` and `u128`.
struct TagOrContentVisitor<'de> {
name: &'static str,
value: PhantomData<TagOrContent<'de>>,
Expand Down Expand Up @@ -814,6 +818,9 @@ mod content {

/// Used by generated code to deserialize an internally tagged enum.
///
/// Captures map or sequence from the original deserializer and searches
/// a tag in it (in case of sequence, tag is the first element of sequence).
///
/// Not public API.
pub struct TaggedContentVisitor<T> {
tag_name: &'static str,
Expand Down
15 changes: 15 additions & 0 deletions test_suite/tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,15 @@ fn test_internally_tagged_struct_variant_containing_unit_variant() {
Log { level: Level },
}

assert_de_tokens(
&Level::Info,
&[
Token::Enum { name: "Level" },
Token::BorrowedStr("Info"),
Token::Unit,
],
);

assert_de_tokens(
&Message::Log { level: Level::Info },
&[
Expand All @@ -1091,7 +1100,9 @@ fn test_internally_tagged_struct_variant_containing_unit_variant() {
Token::Str("action"),
Token::Str("Log"),
Token::Str("level"),
Token::Enum { name: "Level" },
Token::BorrowedStr("Info"),
Token::Unit,
Token::StructEnd,
],
);
Expand All @@ -1103,7 +1114,9 @@ fn test_internally_tagged_struct_variant_containing_unit_variant() {
Token::Str("action"),
Token::Str("Log"),
Token::Str("level"),
Token::Enum { name: "Level" },
Token::BorrowedStr("Info"),
Token::Unit,
Token::MapEnd,
],
);
Expand All @@ -1113,7 +1126,9 @@ fn test_internally_tagged_struct_variant_containing_unit_variant() {
&[
Token::Seq { len: Some(2) },
Token::Str("Log"),
Token::Enum { name: "Level" },
Token::BorrowedStr("Info"),
Token::Unit,
Token::SeqEnd,
],
);
Expand Down

0 comments on commit 00c4b0c

Please sign in to comment.