Skip to content

Commit 1d2dbb8

Browse files
committed
Add regression tests for tafia#567
failures (2): serde-de-seq (1): seq::variable_name::fixed_size::list_of_enum serde-issues (1): issue567
1 parent 73f9286 commit 1d2dbb8

File tree

2 files changed

+83
-4
lines changed

2 files changed

+83
-4
lines changed

tests/serde-de-seq.rs

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ mod fixed_name {
167167
use pretty_assertions::assert_eq;
168168

169169
#[derive(Debug, PartialEq, Deserialize)]
170-
struct List {
171-
item: [(); 3],
170+
struct List<T = ()> {
171+
item: [T; 3],
172172
}
173173

174174
/// Simple case: count of elements matches expected size of sequence,
@@ -796,6 +796,31 @@ mod fixed_name {
796796
);
797797
}
798798

799+
#[test]
800+
fn list_of_list() {
801+
let data: List<Vec<String>> = from_str(
802+
r#"
803+
<root>
804+
<item>first item</item>
805+
<item>second item</item>
806+
<item>third item</item>
807+
</root>
808+
"#,
809+
)
810+
.unwrap();
811+
812+
assert_eq!(
813+
data,
814+
List {
815+
item: [
816+
vec!["first".to_string(), "item".to_string()],
817+
vec!["second".to_string(), "item".to_string()],
818+
vec!["third".to_string(), "item".to_string()],
819+
],
820+
}
821+
);
822+
}
823+
799824
/// Checks that sequences represented by elements can contain sequences,
800825
/// represented by [`xs:list`s](https://www.w3schools.com/xml/el_list.asp)
801826
mod xs_list {
@@ -1889,9 +1914,9 @@ mod variable_name {
18891914
use pretty_assertions::assert_eq;
18901915

18911916
#[derive(Debug, PartialEq, Deserialize)]
1892-
struct List {
1917+
struct List<T = Choice> {
18931918
#[serde(rename = "$value")]
1894-
item: [Choice; 3],
1919+
item: [T; 3],
18951920
}
18961921

18971922
/// Simple case: count of elements matches expected size of sequence,
@@ -2890,6 +2915,37 @@ mod variable_name {
28902915
.unwrap_err();
28912916
}
28922917

2918+
/// Test for https://github.com/tafia/quick-xml/issues/567
2919+
#[test]
2920+
fn list_of_enum() {
2921+
#[derive(Debug, PartialEq, Deserialize)]
2922+
enum Enum {
2923+
Variant(Vec<String>),
2924+
}
2925+
2926+
let data: List<Enum> = from_str(
2927+
r#"
2928+
<root>
2929+
<Variant>first item</Variant>
2930+
<Variant>second item</Variant>
2931+
<Variant>third item</Variant>
2932+
</root>
2933+
"#,
2934+
)
2935+
.unwrap();
2936+
2937+
assert_eq!(
2938+
data,
2939+
List {
2940+
item: [
2941+
Enum::Variant(vec!["first".to_string(), "item".to_string()]),
2942+
Enum::Variant(vec!["second".to_string(), "item".to_string()]),
2943+
Enum::Variant(vec!["third".to_string(), "item".to_string()]),
2944+
],
2945+
}
2946+
);
2947+
}
2948+
28932949
/// Checks that sequences represented by elements can contain sequences,
28942950
/// represented by `xs:list`s
28952951
mod xs_list {

tests/serde-issues.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ mod issue537 {
354354
}
355355
}
356356

357+
/// Regression test for https://github.com/tafia/quick-xml/issues/540.
357358
#[test]
358359
fn issue540() {
359360
#[derive(Serialize)]
@@ -379,6 +380,28 @@ fn issue540() {
379380
);
380381
}
381382

383+
/// Regression test for https://github.com/tafia/quick-xml/issues/567.
384+
#[test]
385+
fn issue567() {
386+
#[derive(Debug, Deserialize, PartialEq)]
387+
struct Root {
388+
#[serde(rename = "$value")]
389+
items: Vec<Enum>,
390+
}
391+
392+
#[derive(Debug, Deserialize, PartialEq)]
393+
enum Enum {
394+
List(Vec<()>),
395+
}
396+
397+
assert_eq!(
398+
from_str::<Root>("<root><List/></root>").unwrap(),
399+
Root {
400+
items: vec![Enum::List(vec![])],
401+
}
402+
);
403+
}
404+
382405
/// Regression test for https://github.com/tafia/quick-xml/issues/580.
383406
#[test]
384407
fn issue580() {

0 commit comments

Comments
 (0)