Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate and add new tests of internally tagged enums #2788

Merged
merged 22 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
aa06543
Convert test_internally_tagged_enum into module
Mingun Apr 22, 2023
99f9054
Move all internally tagged enum tests of `test_macros` into a dedicat…
Mingun Jul 27, 2023
da0ed40
Give meaningful names to enum variants
Mingun Apr 22, 2023
8c60f5a
Reorder enum variants and tests to canonical order (Unit, Newtype, Tu…
Mingun Apr 22, 2023
0939214
Move internally tagged enum tests into a dedicated file
Mingun Jul 27, 2023
2cbfd37
Move all other internally tagged enum tests into a dedicated file
Mingun Jul 27, 2023
9128201
Use the same order of derives
Mingun Aug 7, 2023
eb59c77
Use name "tag" to refer to tag field
Mingun Aug 7, 2023
f97160f
Reuse type in unit_variant_with_unknown_fields and add test for sequence
Mingun Aug 7, 2023
2d75ef6
Reuse type in newtype_variant_containing_unit
Mingun Aug 7, 2023
93bda5f
Rename unit struct to a generic name: Info->Unit
Mingun Aug 7, 2023
48de0c5
Share unit struct Unit between all tests
Mingun Aug 7, 2023
d3492d8
Reuse type in newtype_variant_containing_unit_struct
Mingun Aug 7, 2023
e999600
Rename externally tagged enum Inner to Enum
Mingun Aug 7, 2023
28a775d
Share externally tagged enum Enum between all tests and reuse in stru…
Mingun Aug 7, 2023
41b9c33
Reuse type in newtype_variant_containing_externally_tagged_enum
Mingun Aug 7, 2023
7c0e6bd
Reuse type in struct_variant_containing_unit_variant
Mingun Aug 7, 2023
8bfe0d0
Move and rename tests:
Mingun Aug 7, 2023
4987fd1
Convert newtype_enum and struct_enum tests into modules
Mingun Aug 7, 2023
4795450
Add tests with borrowed strings for the tag field name and tag value
Mingun Aug 7, 2023
71ed1f2
Add tests for special and general cases for internally tagged enums
Mingun Oct 3, 2022
2adb0e9
Add additional checks for unit and newtype_unit tests
Mingun Aug 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 0 additions & 133 deletions test_suite/tests/test_annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1607,58 +1607,6 @@ fn test_collect_other() {
);
}

#[test]
fn test_internally_tagged_enum_with_skipped_conflict() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[serde(tag = "t")]
enum Data {
A,
#[serde(skip)]
#[allow(dead_code)]
B {
t: String,
},
C {
#[serde(default, skip)]
t: String,
},
}

let data = Data::C { t: String::new() };

assert_tokens(
&data,
&[
Token::Struct {
name: "Data",
len: 1,
},
Token::Str("t"),
Token::Str("C"),
Token::StructEnd,
],
);
}

#[test]
fn test_internally_tagged_enum_new_type_with_unit() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[serde(tag = "t")]
enum Data {
A(()),
}

assert_tokens(
&Data::A(()),
&[
Token::Map { len: Some(1) },
Token::Str("t"),
Token::Str("A"),
Token::MapEnd,
],
);
}

#[test]
fn test_adjacently_tagged_enum_bytes() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
Expand Down Expand Up @@ -1968,29 +1916,6 @@ fn test_transparent_tuple_struct() {
assert_tokens(&Transparent(false, 1, false, PhantomData), &[Token::U32(1)]);
}

#[test]
fn test_internally_tagged_unit_enum_with_unknown_fields() {
#[derive(Deserialize, PartialEq, Debug)]
#[serde(tag = "t")]
enum Data {
A,
}

let data = Data::A;

assert_de_tokens(
&data,
&[
Token::Map { len: None },
Token::Str("t"),
Token::Str("A"),
Token::Str("b"),
Token::I32(0),
Token::MapEnd,
],
);
}

#[test]
fn test_expecting_message() {
#[derive(Deserialize, PartialEq, Debug)]
Expand Down Expand Up @@ -2055,27 +1980,6 @@ fn test_expecting_message_externally_tagged_enum() {
);
}

#[test]
fn test_expecting_message_internally_tagged_enum() {
#[derive(Deserialize)]
#[serde(tag = "tag")]
#[serde(expecting = "something strange...")]
enum Enum {
InternallyTagged,
}

assert_de_tokens_error::<Enum>(
&[Token::Str("InternallyTagged")],
r#"invalid type: string "InternallyTagged", expected something strange..."#,
);

// Check that #[serde(expecting = "...")] doesn't affect variant identifier error message
assert_de_tokens_error::<Enum>(
&[Token::Map { len: None }, Token::Str("tag"), Token::Unit],
"invalid type: unit value, expected variant identifier",
);
}

#[test]
fn test_expecting_message_adjacently_tagged_enum() {
#[derive(Deserialize)]
Expand Down Expand Up @@ -3123,43 +3027,6 @@ mod flatten {
mod internally_tagged {
use super::*;

#[test]
fn straightforward() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[serde(tag = "t")]
enum Data {
A {
a: i32,
#[serde(flatten)]
flat: Flat,
},
}

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Flat {
b: i32,
}

let data = Data::A {
a: 0,
flat: Flat { b: 0 },
};

assert_tokens(
&data,
&[
Token::Map { len: None },
Token::Str("t"),
Token::Str("A"),
Token::Str("a"),
Token::I32(0),
Token::Str("b"),
Token::I32(0),
Token::MapEnd,
],
);
}

#[test]
fn structs() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down
Loading