Skip to content

Commit 77cdb0f

Browse files
committed
Add tests for deserialization of sequences from empty xs:list representation
failures: ---- fixed_name::fixed_size::xs_list::empty stdout ---- [tests\helpers\mod.rs:14] source = "\n <root>\n <item/>\n </root>\n " thread 'fixed_name::fixed_size::xs_list::empty' panicked at tests/serde-de-seq.rs:871:18: called `Result::unwrap()` on an `Err` value: UnexpectedEof note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ---- fixed_name::variable_size::xs_list::empty stdout ---- [tests\helpers\mod.rs:14] source = "\n <root>\n <item/>\n </root>\n " thread 'fixed_name::variable_size::xs_list::empty' panicked at tests/serde-de-seq.rs:1697:18: called `Result::unwrap()` on an `Err` value: UnexpectedEof ---- variable_name::fixed_size::xs_list::empty stdout ---- [tests\helpers\mod.rs:14] source = "\n <root>\n <item/>\n </root>\n " thread 'variable_name::fixed_size::xs_list::empty' panicked at tests/serde-de-seq.rs:2967:18: called `Result::unwrap()` on an `Err` value: UnexpectedEof ---- variable_name::variable_size::xs_list::empty stdout ---- [tests\helpers\mod.rs:14] source = "\n <root>\n <item/>\n </root>\n " thread 'variable_name::variable_size::xs_list::empty' panicked at tests/serde-de-seq.rs:4066:18: called `Result::unwrap()` on an `Err` value: UnexpectedEof failures: fixed_name::fixed_size::xs_list::empty fixed_name::variable_size::xs_list::empty variable_name::fixed_size::xs_list::empty variable_name::variable_size::xs_list::empty
1 parent c1cd2e5 commit 77cdb0f

File tree

1 file changed

+84
-19
lines changed

1 file changed

+84
-19
lines changed

tests/serde-de-seq.rs

+84-19
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,15 @@ mod fixed_name {
802802
use super::*;
803803
use pretty_assertions::assert_eq;
804804

805+
#[derive(Debug, Deserialize, PartialEq)]
806+
struct List {
807+
/// Outer list mapped to elements, inner -- to `xs:list`.
808+
///
809+
/// `#[serde(default)]` is not required, because correct
810+
/// XML will always contains at least 1 element.
811+
item: [Vec<String>; 1],
812+
}
813+
805814
/// Special case: zero elements
806815
#[test]
807816
fn zero() {
@@ -832,15 +841,6 @@ mod fixed_name {
832841
/// Special case: one element
833842
#[test]
834843
fn one() {
835-
#[derive(Debug, Deserialize, PartialEq)]
836-
struct List {
837-
/// Outer list mapped to elements, inner -- to `xs:list`.
838-
///
839-
/// `#[serde(default)]` is not required, because correct
840-
/// XML will always contains at least 1 element.
841-
item: [Vec<String>; 1],
842-
}
843-
844844
let data: List = from_str(
845845
r#"
846846
<root>
@@ -858,6 +858,21 @@ mod fixed_name {
858858
);
859859
}
860860

861+
/// Special case: empty `xs:list`
862+
#[test]
863+
fn empty() {
864+
let data: List = from_str(
865+
r#"
866+
<root>
867+
<item/>
868+
</root>
869+
"#,
870+
)
871+
.unwrap();
872+
873+
assert_eq!(data, List { item: [vec![]] });
874+
}
875+
861876
/// Special case: outer list is always mapped to an elements sequence,
862877
/// not to an `xs:list`
863878
#[test]
@@ -1669,6 +1684,21 @@ mod fixed_name {
16691684
);
16701685
}
16711686

1687+
/// Special case: empty `xs:list`
1688+
#[test]
1689+
fn empty() {
1690+
let data: List = from_str(
1691+
r#"
1692+
<root>
1693+
<item/>
1694+
</root>
1695+
"#,
1696+
)
1697+
.unwrap();
1698+
1699+
assert_eq!(data, List { item: vec![vec![]] });
1700+
}
1701+
16721702
/// Special case: outer list is always mapped to an elements sequence,
16731703
/// not to an `xs:list`
16741704
#[test]
@@ -2866,6 +2896,16 @@ mod variable_name {
28662896
use super::*;
28672897
use pretty_assertions::assert_eq;
28682898

2899+
#[derive(Debug, Deserialize, PartialEq)]
2900+
struct List {
2901+
/// Outer list mapped to elements, inner -- to `xs:list`.
2902+
///
2903+
/// `#[serde(default)]` is not required, because correct
2904+
/// XML will always contains at least 1 element.
2905+
#[serde(rename = "$value")]
2906+
element: [Vec<String>; 1],
2907+
}
2908+
28692909
/// Special case: zero elements
28702910
#[test]
28712911
fn zero() {
@@ -2897,16 +2937,6 @@ mod variable_name {
28972937
/// Special case: one element
28982938
#[test]
28992939
fn one() {
2900-
#[derive(Debug, Deserialize, PartialEq)]
2901-
struct List {
2902-
/// Outer list mapped to elements, inner -- to `xs:list`.
2903-
///
2904-
/// `#[serde(default)]` is not required, because correct
2905-
/// XML will always contains at least 1 element.
2906-
#[serde(rename = "$value")]
2907-
element: [Vec<String>; 1],
2908-
}
2909-
29102940
let data: List = from_str(
29112941
r#"
29122942
<root>
@@ -2924,6 +2954,21 @@ mod variable_name {
29242954
);
29252955
}
29262956

2957+
/// Special case: empty `xs:list`
2958+
#[test]
2959+
fn empty() {
2960+
let data: List = from_str(
2961+
r#"
2962+
<root>
2963+
<item/>
2964+
</root>
2965+
"#,
2966+
)
2967+
.unwrap();
2968+
2969+
assert_eq!(data, List { element: [vec![]] });
2970+
}
2971+
29272972
/// Special case: outer list is always mapped to an elements sequence,
29282973
/// not to an `xs:list`
29292974
#[test]
@@ -4008,6 +4053,26 @@ mod variable_name {
40084053
);
40094054
}
40104055

4056+
/// Special case: empty `xs:list`
4057+
#[test]
4058+
fn empty() {
4059+
let data: List = from_str(
4060+
r#"
4061+
<root>
4062+
<item/>
4063+
</root>
4064+
"#,
4065+
)
4066+
.unwrap();
4067+
4068+
assert_eq!(
4069+
data,
4070+
List {
4071+
element: vec![vec![]]
4072+
}
4073+
);
4074+
}
4075+
40114076
/// Special case: outer list is always mapped to an elements sequence,
40124077
/// not to an `xs:list`
40134078
#[test]

0 commit comments

Comments
 (0)