summaryrefslogtreecommitdiffstats
path: root/third_party/rust/serde_repr/tests/test.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/serde_repr/tests/test.rs
parentInitial commit. (diff)
downloadfirefox-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/test.rs')
-rw-r--r--third_party/rust/serde_repr/tests/test.rs81
1 files changed, 81 insertions, 0 deletions
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);
+ }
+}