Remove Vec tests from entities
This commit is contained in:
parent
1e3ae38b25
commit
284a015bf8
|
@ -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><>&"'adsad"</string><str>str</str><cow>str&</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><>&"'adsad"</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><>&"'adsad"</string><str>str</str><cow>str&</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><>&"'adsad"</string><str>str&</str><vec><element xmlns=\"\">one</element><element xmlns=\"\">two</element><element xmlns=\"\">three</element></vec></StructSpecialEntities>"
|
"<StructSpecialEntities xmlns=\"URI\"><string><>&"'adsad"</string><str>str&</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><>&"'adsad"</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><>&"'adsad"</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><>&"'adsad"</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><>&"'adsad"</string><str>str</str><cow>str&</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>&"<>'aa</string><str>&"<>'bb</str><cow>&"<>'cc</cow><vec><element xmlns=\"\">one</element><element xmlns=\"\">two</element><element xmlns=\"\">three</element></vec></StructSpecialEntities>",
|
"<StructSpecialEntities xmlns=\"URI\"><string>&"<>'aa</string><str>&"<>'bb</str><cow>&"<>'cc</cow></StructSpecialEntities>",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue