From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/ron/tests/extensions.rs | 91 ++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 third_party/rust/ron/tests/extensions.rs (limited to 'third_party/rust/ron/tests/extensions.rs') diff --git a/third_party/rust/ron/tests/extensions.rs b/third_party/rust/ron/tests/extensions.rs new file mode 100644 index 0000000000..6161d90b43 --- /dev/null +++ b/third_party/rust/ron/tests/extensions.rs @@ -0,0 +1,91 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Debug, PartialEq, Deserialize, Serialize)] +struct UnitStruct; + +#[derive(Debug, PartialEq, Deserialize, Serialize)] +struct NewType(f32); + +#[derive(Debug, PartialEq, Deserialize, Serialize)] +struct TupleStruct(UnitStruct, i8); + +#[derive(Debug, PartialEq, Eq, Hash, Deserialize, Serialize)] +struct Key(u32); + +#[derive(Debug, PartialEq, Eq, Hash, Deserialize, Serialize)] +enum Enum { + Unit, + Bool(bool), + Chars(char, String), +} + +#[derive(Debug, PartialEq, Deserialize, Serialize)] +struct Struct { + tuple: ((), NewType, TupleStruct), + vec: Vec>, + map: HashMap, +} + +const CONFIG_U_NT: &str = " +#![enable(unwrap_newtypes)] + +( + tuple: ((), 0.5, ((), -5)), + vec: [ + None, + Some(()), + ], + map: { + 7: Bool(true), + 9: Chars('x', \"\"), + 6: Bool(false), + 5: Unit, + }, +) +"; + +#[test] +fn unwrap_newtypes() { + let d: Struct = ron::de::from_str(CONFIG_U_NT).expect("Failed to deserialize"); + + println!("unwrap_newtypes: {:#?}", d); + + let s = ron::ser::to_string_pretty( + &d, + ron::ser::PrettyConfig::default().extensions(ron::extensions::Extensions::UNWRAP_NEWTYPES), + ) + .expect("Failed to serialize"); + + let d2: Struct = ron::de::from_str(&s).expect("Failed to deserialize"); + + assert_eq!(d, d2); +} + +const CONFIG_I_S: &str = " +#![enable(implicit_some)] + +( + tuple: ((), (0.5), ((), -5)), + vec: [ + None, + (), + UnitStruct, + None, + (), + ], + map: { + (7): Bool(true), + (9): Chars('x', \"\"), + (6): Bool(false), + (5): Unit, + }, +) +"; + +#[test] +fn implicit_some() { + let d: Struct = ron::de::from_str(CONFIG_I_S).expect("Failed to deserialize"); + + println!("implicit_some: {:#?}", d); +} -- cgit v1.2.3