Skip to content

Commit

Permalink
Add regression tests for tafia#567
Browse files Browse the repository at this point in the history
failures (2):
  serde-de-seq (1):
    seq::variable_name::fixed_size::list_of_enum
  serde-issues (1):
    issue567
  • Loading branch information
Mingun committed Oct 9, 2023
1 parent 73f9286 commit 1d2dbb8
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
64 changes: 60 additions & 4 deletions tests/serde-de-seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ mod fixed_name {
use pretty_assertions::assert_eq;

#[derive(Debug, PartialEq, Deserialize)]
struct List {
item: [(); 3],
struct List<T = ()> {
item: [T; 3],
}

/// Simple case: count of elements matches expected size of sequence,
Expand Down Expand Up @@ -796,6 +796,31 @@ mod fixed_name {
);
}

#[test]
fn list_of_list() {
let data: List<Vec<String>> = from_str(
r#"
<root>
<item>first item</item>
<item>second item</item>
<item>third item</item>
</root>
"#,
)
.unwrap();

assert_eq!(
data,
List {
item: [
vec!["first".to_string(), "item".to_string()],
vec!["second".to_string(), "item".to_string()],
vec!["third".to_string(), "item".to_string()],
],
}
);
}

/// Checks that sequences represented by elements can contain sequences,
/// represented by [`xs:list`s](https://www.w3schools.com/xml/el_list.asp)
mod xs_list {
Expand Down Expand Up @@ -1889,9 +1914,9 @@ mod variable_name {
use pretty_assertions::assert_eq;

#[derive(Debug, PartialEq, Deserialize)]
struct List {
struct List<T = Choice> {
#[serde(rename = "$value")]
item: [Choice; 3],
item: [T; 3],
}

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

/// Test for https://github.com/tafia/quick-xml/issues/567
#[test]
fn list_of_enum() {
#[derive(Debug, PartialEq, Deserialize)]
enum Enum {
Variant(Vec<String>),
}

let data: List<Enum> = from_str(
r#"
<root>
<Variant>first item</Variant>
<Variant>second item</Variant>
<Variant>third item</Variant>
</root>
"#,
)
.unwrap();

assert_eq!(
data,
List {
item: [
Enum::Variant(vec!["first".to_string(), "item".to_string()]),
Enum::Variant(vec!["second".to_string(), "item".to_string()]),
Enum::Variant(vec!["third".to_string(), "item".to_string()]),
],
}
);
}

/// Checks that sequences represented by elements can contain sequences,
/// represented by `xs:list`s
mod xs_list {
Expand Down
23 changes: 23 additions & 0 deletions tests/serde-issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ mod issue537 {
}
}

/// Regression test for https://github.com/tafia/quick-xml/issues/540.
#[test]
fn issue540() {
#[derive(Serialize)]
Expand All @@ -379,6 +380,28 @@ fn issue540() {
);
}

/// Regression test for https://github.com/tafia/quick-xml/issues/567.
#[test]
fn issue567() {
#[derive(Debug, Deserialize, PartialEq)]
struct Root {
#[serde(rename = "$value")]
items: Vec<Enum>,
}

#[derive(Debug, Deserialize, PartialEq)]
enum Enum {
List(Vec<()>),
}

assert_eq!(
from_str::<Root>("<root><List/></root>").unwrap(),
Root {
items: vec![Enum::List(vec![])],
}
);
}

/// Regression test for https://github.com/tafia/quick-xml/issues/580.
#[test]
fn issue580() {
Expand Down

0 comments on commit 1d2dbb8

Please sign in to comment.