summaryrefslogtreecommitdiffstats
path: root/third_party/rust/serde_yaml/tests/test_value.rs
diff options
context:
space:
mode:
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
+ }
+ );
+}