Remove Vec tests from entities

This commit is contained in:
Dirkjan Ochtman 2022-11-24 21:27:22 -08:00
parent 1e3ae38b25
commit 284a015bf8
1 changed files with 5 additions and 35 deletions

View File

@ -10,61 +10,32 @@ struct StructSpecialEntities<'a> {
string: String, string: String,
str: &'a str, str: &'a str,
cow: Cow<'a, str>, cow: Cow<'a, str>,
vec: Vec<String>,
}
#[derive(Debug, PartialEq, Eq, FromXml, ToXml)]
#[xml(ns("URI"))]
struct VecEntities<'a> {
complex: Vec<StructSpecialEntities<'a>>,
list1: Vec<String>,
list2: Vec<Vec<String>>,
}
#[test]
fn vec_entities() {
let serialized = r#"<VecEntities xmlns="URI"><complex><StructSpecialEntities><string>&lt;&gt;&amp;&quot;&apos;adsad&quot;</string><str>str</str><cow>str&amp;</cow><vec><element xmlns="">one</element><element xmlns="">two</element><element xmlns="">three</element></vec></StructSpecialEntities></complex><list1><element xmlns="">a</element><element xmlns="">b</element></list1><list2><list xmlns=""><element xmlns="">a</element><element xmlns="">b</element></list></list2></VecEntities>"#;
let instance = VecEntities {
complex: vec![StructSpecialEntities {
string: String::from("<>&\"'adsad\""),
str: "str",
cow: Cow::Owned("str&".to_string()),
vec: vec!["one".into(), "two".into(), "three".into()],
}],
list1: vec!["a".into(), "b".into()],
list2: vec![vec!["a".into(), "b".into()]],
};
assert_eq!(to_string(&instance).unwrap(), serialized);
assert_eq!(from_str(serialized), Ok(instance));
} }
#[test] #[test]
fn escape_back() { fn escape_back() {
assert_eq!( assert_eq!(
from_str( from_str(
"<StructSpecialEntities xmlns=\"URI\"><string>&lt;&gt;&amp;&quot;&apos;adsad&quot;</string><str>str</str><cow>str&amp;</cow><vec><element xmlns=\"\">one</element><element xmlns=\"\">two</element><element xmlns=\"\">three</element></vec></StructSpecialEntities>" "<StructSpecialEntities xmlns=\"URI\"><string>&lt;&gt;&amp;&quot;&apos;adsad&quot;</string><str>str</str><cow>str&amp;</cow></StructSpecialEntities>"
), ),
Ok(StructSpecialEntities { Ok(StructSpecialEntities {
string: String::from("<>&\"'adsad\""), string: String::from("<>&\"'adsad\""),
str: "str", str: "str",
cow: Cow::Owned("str&".to_string()), cow: Cow::Owned("str&".to_string()),
vec: vec!["one".into(), "two".into(), "three".into()]
}) })
); );
// Wrong str char // Wrong str char
assert_eq!( assert_eq!(
from_str( from_str(
"<StructSpecialEntities xmlns=\"URI\"><string>&lt;&gt;&amp;&quot;&apos;adsad&quot;</string><str>str&amp;</str><vec><element xmlns=\"\">one</element><element xmlns=\"\">two</element><element xmlns=\"\">three</element></vec></StructSpecialEntities>" "<StructSpecialEntities xmlns=\"URI\"><string>&lt;&gt;&amp;&quot;&apos;adsad&quot;</string><str>str&amp;</str></StructSpecialEntities>"
), ),
Err::<StructSpecialEntities, _>(Error::UnexpectedValue) Err::<StructSpecialEntities, _>(Error::UnexpectedValue)
); );
// Borrowed // Borrowed
let escape_back = from_str::<StructSpecialEntities>( let escape_back = from_str::<StructSpecialEntities>(
"<StructSpecialEntities xmlns=\"URI\"><string>&lt;&gt;&amp;&quot;&apos;adsad&quot;</string><str>str</str><cow>str</cow><vec><element xmlns=\"\">one</element><element xmlns=\"\">two</element><element xmlns=\"\">three</element></vec></StructSpecialEntities>" "<StructSpecialEntities xmlns=\"URI\"><string>&lt;&gt;&amp;&quot;&apos;adsad&quot;</string><str>str</str><cow>str</cow></StructSpecialEntities>"
) )
.unwrap(); .unwrap();
@ -74,7 +45,7 @@ fn escape_back() {
// Owned // Owned
let escape_back = from_str::<StructSpecialEntities>( let escape_back = from_str::<StructSpecialEntities>(
"<StructSpecialEntities xmlns=\"URI\"><string>&lt;&gt;&amp;&quot;&apos;adsad&quot;</string><str>str</str><cow>str&amp;</cow><vec><element xmlns=\"\">one</element><element xmlns=\"\">two</element><element xmlns=\"\">three</element></vec></StructSpecialEntities>" "<StructSpecialEntities xmlns=\"URI\"><string>&lt;&gt;&amp;&quot;&apos;adsad&quot;</string><str>str</str><cow>str&amp;</cow></StructSpecialEntities>"
) )
.unwrap(); .unwrap();
@ -90,8 +61,7 @@ fn special_entities() {
string: "&\"<>\'aa".to_string(), string: "&\"<>\'aa".to_string(),
str: "&\"<>\'bb", str: "&\"<>\'bb",
cow: Cow::from("&\"<>\'cc"), cow: Cow::from("&\"<>\'cc"),
vec: vec!["one".into(), "two".into(), "three".into()]
}).unwrap(), }).unwrap(),
"<StructSpecialEntities xmlns=\"URI\"><string>&amp;&quot;&lt;&gt;&apos;aa</string><str>&amp;&quot;&lt;&gt;&apos;bb</str><cow>&amp;&quot;&lt;&gt;&apos;cc</cow><vec><element xmlns=\"\">one</element><element xmlns=\"\">two</element><element xmlns=\"\">three</element></vec></StructSpecialEntities>", "<StructSpecialEntities xmlns=\"URI\"><string>&amp;&quot;&lt;&gt;&apos;aa</string><str>&amp;&quot;&lt;&gt;&apos;bb</str><cow>&amp;&quot;&lt;&gt;&apos;cc</cow></StructSpecialEntities>",
); );
} }