@@ -43,115 +43,6 @@ fn string_borrow() {
43
43
assert_eq ! ( borrowed_item. text, "Hello world" ) ;
44
44
}
45
45
46
- #[ derive( Debug , Deserialize , PartialEq ) ]
47
- struct Item {
48
- name : String ,
49
- source : String ,
50
- }
51
-
52
- #[ test]
53
- fn multiple_roots_attributes ( ) {
54
- let item: Vec < Item > = from_str (
55
- r#"
56
- <item name="hello1" source="world1.rs" />
57
- <item name="hello2" source="world2.rs" />
58
- "# ,
59
- )
60
- . unwrap ( ) ;
61
- assert_eq ! (
62
- item,
63
- vec![
64
- Item {
65
- name: "hello1" . to_string( ) ,
66
- source: "world1.rs" . to_string( ) ,
67
- } ,
68
- Item {
69
- name: "hello2" . to_string( ) ,
70
- source: "world2.rs" . to_string( ) ,
71
- } ,
72
- ]
73
- ) ;
74
- }
75
-
76
- #[ test]
77
- fn nested_collection ( ) {
78
- #[ derive( Debug , Deserialize , PartialEq ) ]
79
- struct Project {
80
- name : String ,
81
-
82
- #[ serde( rename = "item" , default ) ]
83
- items : Vec < Item > ,
84
- }
85
-
86
- let project: Project = from_str (
87
- r#"
88
- <project name="my_project">
89
- <item name="hello1" source="world1.rs" />
90
- <item name="hello2" source="world2.rs" />
91
- </project>
92
- "# ,
93
- )
94
- . unwrap ( ) ;
95
- assert_eq ! (
96
- project,
97
- Project {
98
- name: "my_project" . to_string( ) ,
99
- items: vec![
100
- Item {
101
- name: "hello1" . to_string( ) ,
102
- source: "world1.rs" . to_string( ) ,
103
- } ,
104
- Item {
105
- name: "hello2" . to_string( ) ,
106
- source: "world2.rs" . to_string( ) ,
107
- } ,
108
- ] ,
109
- }
110
- ) ;
111
- }
112
-
113
- #[ test]
114
- fn collection_of_enums ( ) {
115
- #[ derive( Debug , Deserialize , PartialEq ) ]
116
- enum MyEnum {
117
- A ( String ) ,
118
- B { name : String , flag : bool } ,
119
- C ,
120
- }
121
-
122
- #[ derive( Debug , Deserialize , PartialEq ) ]
123
- struct MyEnums {
124
- // TODO: This should be #[serde(flatten)], but right now serde don't support flattening of sequences
125
- // See https://github.com/serde-rs/serde/issues/1905
126
- #[ serde( rename = "$value" ) ]
127
- items : Vec < MyEnum > ,
128
- }
129
-
130
- let s = r#"
131
- <enums>
132
- <A>test</A>
133
- <B name="hello" flag="t" />
134
- <C />
135
- </enums>
136
- "# ;
137
-
138
- let project: MyEnums = from_str ( s) . unwrap ( ) ;
139
-
140
- assert_eq ! (
141
- project,
142
- MyEnums {
143
- items: vec![
144
- MyEnum :: A ( "test" . to_string( ) ) ,
145
- MyEnum :: B {
146
- name: "hello" . to_string( ) ,
147
- flag: true ,
148
- } ,
149
- MyEnum :: C ,
150
- ] ,
151
- }
152
- ) ;
153
- }
154
-
155
46
/// Test for https://github.com/tafia/quick-xml/issues/231
156
47
#[ test]
157
48
fn implicit_value ( ) {
@@ -3589,6 +3480,18 @@ macro_rules! maplike_errors {
3589
3480
mod non_closed {
3590
3481
use super :: * ;
3591
3482
3483
+ /// For struct we expect that error about not closed tag appears
3484
+ /// earlier than error about missing fields
3485
+ #[ test]
3486
+ fn missing_field( ) {
3487
+ let data = from_str:: <$type>( r#"<root>"# ) ;
3488
+
3489
+ match data {
3490
+ Err ( DeError :: UnexpectedEof ) => ( ) ,
3491
+ _ => panic!( "Expected `UnexpectedEof`, found {:?}" , data) ,
3492
+ }
3493
+ }
3494
+
3592
3495
#[ test]
3593
3496
fn attributes( ) {
3594
3497
let data = from_str:: <$type>( r#"<root float="42" string="answer">"# ) ;
@@ -3624,6 +3527,18 @@ macro_rules! maplike_errors {
3624
3527
use super :: * ;
3625
3528
use quick_xml:: Error :: EndEventMismatch ;
3626
3529
3530
+ /// For struct we expect that error about mismatched tag appears
3531
+ /// earlier than error about missing fields
3532
+ #[ test]
3533
+ fn missing_field( ) {
3534
+ let data = from_str:: <$type>( r#"<root></mismatched>"# ) ;
3535
+
3536
+ match data {
3537
+ Err ( DeError :: InvalidXml ( EndEventMismatch { .. } ) ) => ( ) ,
3538
+ _ => panic!( "Expected `InvalidXml(EndEventMismatch)`, found {:?}" , data) ,
3539
+ }
3540
+ }
3541
+
3627
3542
#[ test]
3628
3543
fn attributes( ) {
3629
3544
let data = from_str:: <$type>(
@@ -3922,6 +3837,12 @@ mod flatten_struct {
3922
3837
mod enum_ {
3923
3838
use super :: * ;
3924
3839
3840
+ #[ derive( Debug , Deserialize , PartialEq ) ]
3841
+ struct Nested {
3842
+ //TODO: change to f64 after fixing https://github.com/serde-rs/serde/issues/1183
3843
+ float : String ,
3844
+ }
3845
+
3925
3846
mod externally_tagged {
3926
3847
use super :: * ;
3927
3848
use pretty_assertions:: assert_eq;
@@ -3947,12 +3868,6 @@ mod enum_ {
3947
3868
} ,
3948
3869
}
3949
3870
3950
- #[ derive( Debug , Deserialize , PartialEq ) ]
3951
- struct Nested {
3952
- //TODO: change to f64 after fixing https://github.com/serde-rs/serde/issues/1183
3953
- float : String ,
3954
- }
3955
-
3956
3871
/// Workaround for serde bug https://github.com/serde-rs/serde/issues/1904
3957
3872
#[ derive( Debug , Deserialize , PartialEq ) ]
3958
3873
enum Workaround {
@@ -4120,12 +4035,6 @@ mod enum_ {
4120
4035
value : bool ,
4121
4036
}
4122
4037
4123
- #[ derive( Debug , Deserialize , PartialEq ) ]
4124
- struct Nested {
4125
- //TODO: change to f64 after fixing https://github.com/serde-rs/serde/issues/1183
4126
- float : String ,
4127
- }
4128
-
4129
4038
mod unit {
4130
4039
use super :: * ;
4131
4040
use pretty_assertions:: assert_eq;
@@ -4306,12 +4215,6 @@ mod enum_ {
4306
4215
} ,
4307
4216
}
4308
4217
4309
- #[ derive( Debug , Deserialize , PartialEq ) ]
4310
- struct Nested {
4311
- //TODO: change to f64 after fixing https://github.com/serde-rs/serde/issues/1183
4312
- float : String ,
4313
- }
4314
-
4315
4218
/// Workaround for serde bug https://github.com/serde-rs/serde/issues/1904
4316
4219
#[ derive( Debug , Deserialize , PartialEq ) ]
4317
4220
#[ serde( tag = "tag" , content = "content" ) ]
@@ -4524,12 +4427,6 @@ mod enum_ {
4524
4427
} ,
4525
4428
}
4526
4429
4527
- #[ derive( Debug , Deserialize , PartialEq ) ]
4528
- struct Nested {
4529
- //TODO: change to f64 after fixing https://github.com/serde-rs/serde/issues/1183
4530
- float : String ,
4531
- }
4532
-
4533
4430
/// Workaround for serde bug https://github.com/serde-rs/serde/issues/1904
4534
4431
#[ derive( Debug , Deserialize , PartialEq ) ]
4535
4432
#[ serde( untagged) ]
0 commit comments