diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/serde_repr/tests | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/serde_repr/tests')
12 files changed, 173 insertions, 0 deletions
diff --git a/third_party/rust/serde_repr/tests/compiletest.rs b/third_party/rust/serde_repr/tests/compiletest.rs new file mode 100644 index 0000000000..7974a6249e --- /dev/null +++ b/third_party/rust/serde_repr/tests/compiletest.rs @@ -0,0 +1,7 @@ +#[rustversion::attr(not(nightly), ignore)] +#[cfg_attr(miri, ignore)] +#[test] +fn ui() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/ui/*.rs"); +} diff --git a/third_party/rust/serde_repr/tests/test.rs b/third_party/rust/serde_repr/tests/test.rs new file mode 100644 index 0000000000..d442448dd5 --- /dev/null +++ b/third_party/rust/serde_repr/tests/test.rs @@ -0,0 +1,81 @@ +#![allow( + clippy::derive_partial_eq_without_eq, + // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 + clippy::nonstandard_macro_braces, + clippy::wildcard_imports, +)] + +use serde_repr::{Deserialize_repr, Serialize_repr}; + +mod small_prime { + use super::*; + + #[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)] + #[repr(u8)] + enum SmallPrime { + Two = 2, + Three = 3, + Five = 5, + Seven = 7, + } + + #[test] + fn test_serialize() { + let j = serde_json::to_string(&SmallPrime::Seven).unwrap(); + assert_eq!(j, "7"); + } + + #[test] + fn test_deserialize() { + let p: SmallPrime = serde_json::from_str("2").unwrap(); + assert_eq!(p, SmallPrime::Two); + } +} + +mod other { + use super::*; + + #[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)] + #[repr(u8)] + enum TestOther { + A, + B, + #[serde(other, rename = "useless")] + Other, + } + + #[test] + fn test_deserialize() { + let p: TestOther = serde_json::from_str("0").unwrap(); + assert_eq!(p, TestOther::A); + let p: TestOther = serde_json::from_str("1").unwrap(); + assert_eq!(p, TestOther::B); + let p: TestOther = serde_json::from_str("5").unwrap(); + assert_eq!(p, TestOther::Other); + } +} + +mod implicit_discriminant { + use super::*; + + #[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)] + #[repr(u8)] + enum ImplicitDiscriminant { + Zero, + One, + Two, + Three, + } + + #[test] + fn test_serialize() { + let j = serde_json::to_string(&ImplicitDiscriminant::Three).unwrap(); + assert_eq!(j, "3"); + } + + #[test] + fn test_deserialize() { + let p: ImplicitDiscriminant = serde_json::from_str("2").unwrap(); + assert_eq!(p, ImplicitDiscriminant::Two); + } +} diff --git a/third_party/rust/serde_repr/tests/ui/empty_enum.rs b/third_party/rust/serde_repr/tests/ui/empty_enum.rs new file mode 100644 index 0000000000..f1fb6f9d56 --- /dev/null +++ b/third_party/rust/serde_repr/tests/ui/empty_enum.rs @@ -0,0 +1,6 @@ +use serde_repr::Serialize_repr; + +#[derive(Serialize_repr)] +enum SmallPrime {} + +fn main() {} diff --git a/third_party/rust/serde_repr/tests/ui/empty_enum.stderr b/third_party/rust/serde_repr/tests/ui/empty_enum.stderr new file mode 100644 index 0000000000..d7c4de19b3 --- /dev/null +++ b/third_party/rust/serde_repr/tests/ui/empty_enum.stderr @@ -0,0 +1,7 @@ +error: there must be at least one variant + --> tests/ui/empty_enum.rs:3:10 + | +3 | #[derive(Serialize_repr)] + | ^^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `Serialize_repr` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/serde_repr/tests/ui/missing_repr.rs b/third_party/rust/serde_repr/tests/ui/missing_repr.rs new file mode 100644 index 0000000000..00836356b9 --- /dev/null +++ b/third_party/rust/serde_repr/tests/ui/missing_repr.rs @@ -0,0 +1,11 @@ +use serde_repr::Serialize_repr; + +#[derive(Serialize_repr)] +enum SmallPrime { + Two = 2, + Three = 3, + Five = 5, + Seven = 7, +} + +fn main() {} diff --git a/third_party/rust/serde_repr/tests/ui/missing_repr.stderr b/third_party/rust/serde_repr/tests/ui/missing_repr.stderr new file mode 100644 index 0000000000..e011be6f1c --- /dev/null +++ b/third_party/rust/serde_repr/tests/ui/missing_repr.stderr @@ -0,0 +1,7 @@ +error: missing #[repr(...)] attribute + --> tests/ui/missing_repr.rs:3:10 + | +3 | #[derive(Serialize_repr)] + | ^^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `Serialize_repr` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/serde_repr/tests/ui/multiple_others.rs b/third_party/rust/serde_repr/tests/ui/multiple_others.rs new file mode 100644 index 0000000000..fdb552b109 --- /dev/null +++ b/third_party/rust/serde_repr/tests/ui/multiple_others.rs @@ -0,0 +1,12 @@ +use serde_repr::Deserialize_repr; + +#[derive(Deserialize_repr)] +#[repr(u8)] +enum MultipleOthers { + #[serde(other)] + A, + #[serde(other)] + B, +} + +fn main() {} diff --git a/third_party/rust/serde_repr/tests/ui/multiple_others.stderr b/third_party/rust/serde_repr/tests/ui/multiple_others.stderr new file mode 100644 index 0000000000..599d5e1724 --- /dev/null +++ b/third_party/rust/serde_repr/tests/ui/multiple_others.stderr @@ -0,0 +1,7 @@ +error: only one variant can be #[serde(other)] + --> tests/ui/multiple_others.rs:3:10 + | +3 | #[derive(Deserialize_repr)] + | ^^^^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `Deserialize_repr` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/serde_repr/tests/ui/non_unit_variant.rs b/third_party/rust/serde_repr/tests/ui/non_unit_variant.rs new file mode 100644 index 0000000000..9cdc80d0af --- /dev/null +++ b/third_party/rust/serde_repr/tests/ui/non_unit_variant.rs @@ -0,0 +1,12 @@ +use serde_repr::Serialize_repr; + +#[derive(Serialize_repr)] +#[repr(u8)] +enum SmallPrime { + Two(u8), + Three(u8), + Five(u8), + Seven(u8), +} + +fn main() {} diff --git a/third_party/rust/serde_repr/tests/ui/non_unit_variant.stderr b/third_party/rust/serde_repr/tests/ui/non_unit_variant.stderr new file mode 100644 index 0000000000..8eaf0c1d9b --- /dev/null +++ b/third_party/rust/serde_repr/tests/ui/non_unit_variant.stderr @@ -0,0 +1,5 @@ +error: must be a unit variant + --> tests/ui/non_unit_variant.rs:6:5 + | +6 | Two(u8), + | ^^^ diff --git a/third_party/rust/serde_repr/tests/ui/not_enum.rs b/third_party/rust/serde_repr/tests/ui/not_enum.rs new file mode 100644 index 0000000000..92a1d746dc --- /dev/null +++ b/third_party/rust/serde_repr/tests/ui/not_enum.rs @@ -0,0 +1,11 @@ +use serde_repr::Serialize_repr; + +#[derive(Serialize_repr)] +struct SmallPrime { + two: u8, + three: u8, + five: u8, + seven: u8, +} + +fn main() {} diff --git a/third_party/rust/serde_repr/tests/ui/not_enum.stderr b/third_party/rust/serde_repr/tests/ui/not_enum.stderr new file mode 100644 index 0000000000..26ad4c313f --- /dev/null +++ b/third_party/rust/serde_repr/tests/ui/not_enum.stderr @@ -0,0 +1,7 @@ +error: input must be an enum + --> tests/ui/not_enum.rs:3:10 + | +3 | #[derive(Serialize_repr)] + | ^^^^^^^^^^^^^^ + | + = note: this error originates in the derive macro `Serialize_repr` (in Nightly builds, run with -Z macro-backtrace for more info) |