summaryrefslogtreecommitdiffstats
path: root/third_party/rust/serde_yaml/tests/test_value.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_yaml/tests/test_value.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/serde_yaml/tests/test_value.rs')
-rw-r--r--third_party/rust/serde_yaml/tests/test_value.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/third_party/rust/serde_yaml/tests/test_value.rs b/third_party/rust/serde_yaml/tests/test_value.rs
new file mode 100644
index 0000000000..c001b9d73d
--- /dev/null
+++ b/third_party/rust/serde_yaml/tests/test_value.rs
@@ -0,0 +1,55 @@
+#![allow(clippy::derive_partial_eq_without_eq, clippy::eq_op)]
+
+use serde::de::IntoDeserializer;
+use serde::Deserialize;
+use serde_derive::Deserialize;
+use serde_yaml::{Number, Value};
+use std::f64;
+
+#[test]
+fn test_nan() {
+ let pos_nan = serde_yaml::from_str::<Value>(".nan").unwrap();
+ assert!(pos_nan.is_f64());
+ assert_eq!(pos_nan, pos_nan);
+
+ let neg_fake_nan = serde_yaml::from_str::<Value>("-.nan").unwrap();
+ assert!(neg_fake_nan.is_string());
+
+ let significand_mask = 0xF_FFFF_FFFF_FFFF;
+ let bits = (f64::NAN.to_bits() ^ significand_mask) | 1;
+ let different_pos_nan = Value::Number(Number::from(f64::from_bits(bits)));
+ assert_eq!(pos_nan, different_pos_nan);
+}
+
+#[test]
+fn test_digits() {
+ let num_string = serde_yaml::from_str::<Value>("01").unwrap();
+ assert!(num_string.is_string());
+}
+
+#[test]
+fn test_into_deserializer() {
+ #[derive(Debug, Deserialize, PartialEq)]
+ struct Test {
+ first: String,
+ second: u32,
+ }
+
+ let value = serde_yaml::from_str::<Value>("xyz").unwrap();
+ let s = String::deserialize(value.into_deserializer()).unwrap();
+ assert_eq!(s, "xyz");
+
+ let value = serde_yaml::from_str::<Value>("- first\n- second\n- third").unwrap();
+ let arr = Vec::<String>::deserialize(value.into_deserializer()).unwrap();
+ assert_eq!(arr, &["first", "second", "third"]);
+
+ let value = serde_yaml::from_str::<Value>("first: abc\nsecond: 99").unwrap();
+ let test = Test::deserialize(value.into_deserializer()).unwrap();
+ assert_eq!(
+ test,
+ Test {
+ first: "abc".to_string(),
+ second: 99
+ }
+ );
+}