@@ -175,43 +175,6 @@ fn array() {
175175}
176176
177177#[ test]
178- fn inner_structs_with_options ( ) {
179- #[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
180- struct Foo {
181- a : Option < Box < Foo > > ,
182- b : Bar ,
183- }
184- #[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
185- struct Bar {
186- a : String ,
187- b : f64 ,
188- }
189-
190- equivalent ! {
191- Foo {
192- a: Some ( Box :: new( Foo {
193- a: None ,
194- b: Bar { a: "foo" . to_owned( ) , b: 4.5 } ,
195- } ) ) ,
196- b: Bar { a: "bar" . to_owned( ) , b: 1.0 } ,
197- } ,
198- map! {
199- a: map! {
200- b: map! {
201- a: crate :: SerdeValue :: String ( "foo" . to_owned( ) ) ,
202- b: crate :: SerdeValue :: Float ( 4.5 )
203- }
204- } ,
205- b: map! {
206- a: crate :: SerdeValue :: String ( "bar" . to_owned( ) ) ,
207- b: crate :: SerdeValue :: Float ( 1.0 )
208- }
209- } ,
210- }
211- }
212-
213- #[ test]
214- #[ cfg( feature = "preserve_order" ) ]
215178fn hashmap ( ) {
216179 use std:: collections:: HashSet ;
217180
@@ -673,26 +636,6 @@ fn empty_arrays() {
673636 }
674637}
675638
676- #[ test]
677- fn empty_arrays2 ( ) {
678- #[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
679- struct Foo {
680- a : Option < Vec < Bar > > ,
681- }
682- #[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
683- struct Bar ;
684-
685- equivalent ! {
686- Foo { a: None } ,
687- map! { } ,
688- }
689-
690- equivalent ! {
691- Foo { a: Some ( vec![ ] ) } ,
692- map! { a: crate :: SerdeValue :: Array ( vec![ ] ) } ,
693- }
694- }
695-
696639#[ test]
697640fn extra_keys ( ) {
698641 #[ derive( Serialize , Deserialize ) ]
@@ -791,44 +734,6 @@ fn newtype_key() {
791734 }
792735}
793736
794- #[ derive( Debug , Default , PartialEq , Serialize , Deserialize ) ]
795- struct CanBeEmpty {
796- a : Option < String > ,
797- b : Option < String > ,
798- }
799-
800- #[ test]
801- fn table_structs_empty ( ) {
802- let input = "[bar]\n \n [baz]\n \n [bazv]\n a = \" foo\" \n \n [foo]\n " ;
803- let value: BTreeMap < String , CanBeEmpty > = crate :: from_str ( input) . unwrap ( ) ;
804- let mut expected: BTreeMap < String , CanBeEmpty > = BTreeMap :: new ( ) ;
805- expected. insert ( "bar" . to_owned ( ) , CanBeEmpty :: default ( ) ) ;
806- expected. insert ( "baz" . to_owned ( ) , CanBeEmpty :: default ( ) ) ;
807- expected. insert (
808- "bazv" . to_owned ( ) ,
809- CanBeEmpty {
810- a : Some ( "foo" . to_owned ( ) ) ,
811- b : None ,
812- } ,
813- ) ;
814- expected. insert ( "foo" . to_owned ( ) , CanBeEmpty :: default ( ) ) ;
815- assert_eq ! ( value, expected) ;
816- assert_data_eq ! (
817- crate :: to_string( & value) . unwrap( ) ,
818- str ![ [ r#"
819- [bar]
820-
821- [baz]
822-
823- [bazv]
824- a = "foo"
825-
826- [foo]
827-
828- "# ] ]
829- ) ;
830- }
831-
832737#[ test]
833738fn fixed_size_array ( ) {
834739 #[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
@@ -1512,6 +1417,110 @@ values = [{ Optional = { x = 0, y = 4 } }, "Empty", { Optional = { x = 2 } }, {
15121417"# ] ] . raw( ) ) ;
15131418}
15141419
1420+ #[ test]
1421+ fn serialize_struct_with_none_string ( ) {
1422+ #[ derive( Debug , Default , PartialEq , Serialize , Deserialize ) ]
1423+ struct CanBeEmpty {
1424+ a : Option < String > ,
1425+ b : Option < String > ,
1426+ }
1427+
1428+ let input = "[bar]
1429+
1430+ [baz]
1431+
1432+ [bazv]
1433+ a = \" foo\"
1434+
1435+ [foo]" ;
1436+ let value: BTreeMap < String , CanBeEmpty > = crate :: from_str ( input) . unwrap ( ) ;
1437+
1438+ let mut expected: BTreeMap < String , CanBeEmpty > = BTreeMap :: new ( ) ;
1439+ expected. insert ( "bar" . to_owned ( ) , CanBeEmpty :: default ( ) ) ;
1440+ expected. insert ( "baz" . to_owned ( ) , CanBeEmpty :: default ( ) ) ;
1441+ expected. insert (
1442+ "bazv" . to_owned ( ) ,
1443+ CanBeEmpty {
1444+ a : Some ( "foo" . to_owned ( ) ) ,
1445+ b : None ,
1446+ } ,
1447+ ) ;
1448+ expected. insert ( "foo" . to_owned ( ) , CanBeEmpty :: default ( ) ) ;
1449+
1450+ assert_eq ! ( value, expected) ;
1451+ assert_data_eq ! (
1452+ crate :: to_string( & value) . unwrap( ) ,
1453+ str ![ [ r#"
1454+ [bar]
1455+
1456+ [baz]
1457+
1458+ [bazv]
1459+ a = "foo"
1460+
1461+ [foo]
1462+
1463+ "# ] ]
1464+ . raw( )
1465+ ) ;
1466+ }
1467+
1468+ #[ test]
1469+ fn serialize_struct_with_none_vec ( ) {
1470+ #[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
1471+ struct Foo {
1472+ a : Option < Vec < Bar > > ,
1473+ }
1474+ #[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
1475+ struct Bar ;
1476+
1477+ equivalent ! {
1478+ Foo { a: None } ,
1479+ map! { } ,
1480+ }
1481+
1482+ equivalent ! {
1483+ Foo { a: Some ( vec![ ] ) } ,
1484+ map! { a: crate :: SerdeValue :: Array ( vec![ ] ) } ,
1485+ }
1486+ }
1487+
1488+ #[ test]
1489+ fn serialize_struct_with_none_struct ( ) {
1490+ #[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
1491+ struct Foo {
1492+ a : Option < Box < Foo > > ,
1493+ b : Bar ,
1494+ }
1495+ #[ derive( Serialize , Deserialize , PartialEq , Debug , Clone ) ]
1496+ struct Bar {
1497+ a : String ,
1498+ b : f64 ,
1499+ }
1500+
1501+ equivalent ! {
1502+ Foo {
1503+ a: Some ( Box :: new( Foo {
1504+ a: None ,
1505+ b: Bar { a: "foo" . to_owned( ) , b: 4.5 } ,
1506+ } ) ) ,
1507+ b: Bar { a: "bar" . to_owned( ) , b: 1.0 } ,
1508+ } ,
1509+ map! {
1510+ a: map! {
1511+ b: map! {
1512+ a: crate :: SerdeValue :: String ( "foo" . to_owned( ) ) ,
1513+ b: crate :: SerdeValue :: Float ( 4.5 )
1514+ }
1515+ } ,
1516+ b: map! {
1517+ a: crate :: SerdeValue :: String ( "bar" . to_owned( ) ) ,
1518+ b: crate :: SerdeValue :: Float ( 1.0 )
1519+ }
1520+ } ,
1521+ }
1522+ }
1523+
15151524#[ test]
15161525fn span_for_sequence_as_map ( ) {
15171526 #[ allow( dead_code) ]
0 commit comments