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-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/serde_repr/tests/test.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
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);
+ }
+}