Skip to content

Commit e9f98cf

Browse files
Mingundralley
authored andcommitted
Add regression test for #343
1 parent 9781b8d commit e9f98cf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/serde-issues.rs

+35
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
//!
33
//! Name each module / test as `issue<GH number>` and keep sorted by issue number
44
5+
use pretty_assertions::assert_eq;
56
use quick_xml::de::from_str;
67
use quick_xml::se::to_string;
78
use serde::{Deserialize, Serialize};
9+
use std::collections::HashMap;
810

911
/// Regression tests for https://github.com/tafia/quick-xml/issues/252.
1012
mod issue252 {
@@ -78,6 +80,39 @@ mod issue252 {
7880
}
7981
}
8082

83+
/// Regression test for https://github.com/tafia/quick-xml/issues/343.
84+
#[test]
85+
fn issue343() {
86+
#[derive(Debug, Deserialize, Serialize, PartialEq)]
87+
struct Users {
88+
users: HashMap<String, User>,
89+
}
90+
#[derive(Debug, Deserialize, Serialize, PartialEq)]
91+
struct Max(u16);
92+
93+
#[derive(Debug, Deserialize, Serialize, PartialEq)]
94+
struct User {
95+
max: Max,
96+
}
97+
98+
let xml = "<Users>\
99+
<users>\
100+
<roger>\
101+
<max>10</max>\
102+
</roger>\
103+
</users>\
104+
</Users>";
105+
let users: Users = from_str(xml).unwrap();
106+
107+
assert_eq!(
108+
users,
109+
Users {
110+
users: HashMap::from([("roger".to_string(), User { max: Max(10) })]),
111+
}
112+
);
113+
assert_eq!(to_string(&users).unwrap(), xml);
114+
}
115+
81116
/// Regression test for https://github.com/tafia/quick-xml/issues/537.
82117
///
83118
/// This test checks that special `xmlns:xxx` attributes uses full name of

0 commit comments

Comments
 (0)