Skip to content

Commit 01caf74

Browse files
committed
Add regression test for tafia#868
failures: serde-de-seq: fixed_name::variable_size::text_and_value variable_name::variable_size::text_and_value serde-issues: issue868
1 parent 19d8512 commit 01caf74

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

tests/serde-issues.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,3 +570,86 @@ fn issue683() {
570570
}
571571
);
572572
}
573+
574+
/// Regression test for https://github.com/tafia/quick-xml/issues/868.
575+
#[test]
576+
fn issue868() {
577+
#[derive(Debug, PartialEq, Deserialize)]
578+
#[serde(rename = "root")]
579+
pub struct Root {
580+
#[serde(rename = "key")]
581+
pub key: Key,
582+
}
583+
584+
#[derive(Debug, PartialEq, Deserialize)]
585+
#[serde(rename = "key")]
586+
pub struct Key {
587+
#[serde(rename = "value")]
588+
pub values: Option<Vec<Value>>,
589+
}
590+
591+
#[derive(Debug, PartialEq, Deserialize)]
592+
#[serde(rename = "Value")]
593+
pub struct Value {
594+
#[serde(rename = "@id")]
595+
pub id: String,
596+
597+
#[serde(rename = "$text")]
598+
pub text: Option<String>,
599+
}
600+
let xml = r#"
601+
<?xml version="1.0" encoding="utf-8"?>
602+
<root>
603+
<key>
604+
<value id="1">text1</value>
605+
<value id="2">text2</value>
606+
<value id="3">text3</value>
607+
<value id="4">text4</value>d
608+
<value id="5">text5</value>
609+
<value id="6">text6</value>
610+
</key>
611+
</root>"#;
612+
let data = quick_xml::de::from_str::<Root>(xml);
613+
#[cfg(feature = "overlapped-lists")]
614+
assert_eq!(
615+
data.unwrap(),
616+
Root {
617+
key: Key {
618+
values: Some(vec![
619+
Value {
620+
id: "1".to_string(),
621+
text: Some("text1".to_string())
622+
},
623+
Value {
624+
id: "2".to_string(),
625+
text: Some("text2".to_string())
626+
},
627+
Value {
628+
id: "3".to_string(),
629+
text: Some("text3".to_string())
630+
},
631+
Value {
632+
id: "4".to_string(),
633+
text: Some("text4".to_string())
634+
},
635+
Value {
636+
id: "5".to_string(),
637+
text: Some("text5".to_string())
638+
},
639+
Value {
640+
id: "6".to_string(),
641+
text: Some("text6".to_string())
642+
},
643+
]),
644+
},
645+
}
646+
);
647+
#[cfg(not(feature = "overlapped-lists"))]
648+
match data {
649+
Err(quick_xml::DeError::Custom(e)) => assert_eq!(e, "duplicate field `value`"),
650+
e => panic!(
651+
r#"Expected `Err(Custom("duplicate field `value`"))`, but got `{:?}`"#,
652+
e
653+
),
654+
}
655+
}

0 commit comments

Comments
 (0)