From ce86f351d6d51eba03fcacc2d7c7cb08965c585d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 8 Mar 2023 19:02:07 -0800 Subject: [PATCH] Make a directory dedicated to regression tests I have had a good experience with this pattern in many of my other libraries. --- test_suite/Cargo.toml | 1 + test_suite/tests/regression.rs | 3 ++ test_suite/tests/regression/issue2371.rs | 43 +++++++++++++++++++++ test_suite/tests/test_gen.rs | 49 ------------------------ 4 files changed, 47 insertions(+), 49 deletions(-) create mode 100644 test_suite/tests/regression.rs create mode 100644 test_suite/tests/regression/issue2371.rs diff --git a/test_suite/Cargo.toml b/test_suite/Cargo.toml index 44b8caa2..656f5ca7 100644 --- a/test_suite/Cargo.toml +++ b/test_suite/Cargo.toml @@ -12,6 +12,7 @@ unstable = ["serde/unstable"] serde = { path = "../serde" } [dev-dependencies] +automod = "1.0" fnv = "1.0" rustversion = "1.0" serde = { path = "../serde", features = ["rc", "derive"] } diff --git a/test_suite/tests/regression.rs b/test_suite/tests/regression.rs new file mode 100644 index 00000000..fb2b25c8 --- /dev/null +++ b/test_suite/tests/regression.rs @@ -0,0 +1,3 @@ +mod regression { + automod::dir!("tests/regression"); +} diff --git a/test_suite/tests/regression/issue2371.rs b/test_suite/tests/regression/issue2371.rs new file mode 100644 index 00000000..5388b595 --- /dev/null +++ b/test_suite/tests/regression/issue2371.rs @@ -0,0 +1,43 @@ +use serde::Deserialize; + +#[derive(Deserialize)] +pub struct Nested; + +#[derive(Deserialize)] +pub enum ExternallyTagged { + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, +} + +#[derive(Deserialize)] +#[serde(tag = "tag")] +pub enum InternallyTagged { + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, +} + +#[derive(Deserialize)] +#[serde(tag = "tag", content = "content")] +pub enum AdjacentlyTagged { + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, +} + +#[derive(Deserialize)] +#[serde(untagged)] +pub enum UntaggedWorkaround { + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, +} diff --git a/test_suite/tests/test_gen.rs b/test_suite/tests/test_gen.rs index 1a1a7d12..c053d690 100644 --- a/test_suite/tests/test_gen.rs +++ b/test_suite/tests/test_gen.rs @@ -892,52 +892,3 @@ pub struct RemotePackedNonCopyDef { impl Drop for RemotePackedNonCopyDef { fn drop(&mut self) {} } - -////////////////////////////////////////////////////////////////////////// - -/// Regression tests for -pub mod static_and_flatten { - use serde::Deserialize; - - #[derive(Deserialize)] - pub struct Nested; - - #[derive(Deserialize)] - pub enum ExternallyTagged { - Flatten { - #[serde(flatten)] - nested: Nested, - string: &'static str, - }, - } - - #[derive(Deserialize)] - #[serde(tag = "tag")] - pub enum InternallyTagged { - Flatten { - #[serde(flatten)] - nested: Nested, - string: &'static str, - }, - } - - #[derive(Deserialize)] - #[serde(tag = "tag", content = "content")] - pub enum AdjacentlyTagged { - Flatten { - #[serde(flatten)] - nested: Nested, - string: &'static str, - }, - } - - #[derive(Deserialize)] - #[serde(untagged)] - pub enum UntaggedWorkaround { - Flatten { - #[serde(flatten)] - nested: Nested, - string: &'static str, - }, - } -}