Rustfmt pass, and rustfmt --check in CI"

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2019-10-23 01:32:41 +02:00
commit a104ebc3f6
No known key found for this signature in database
GPG key ID: DEDA74AEECA9D0F2
79 changed files with 1344 additions and 957 deletions

View file

@ -6,20 +6,18 @@ const TEST_STRING: &'static str = r#"<?xml version="1.0" encoding="utf-8"?><root
fn build_test_tree() -> Element {
let mut root = Element::builder("root")
.ns("root_ns")
.attr("xml:lang", "en")
.attr("a", "b")
.build();
.ns("root_ns")
.attr("xml:lang", "en")
.attr("a", "b")
.build();
root.append_text_node("meow");
let child = Element::builder("child")
.attr("c", "d")
.build();
let child = Element::builder("child").attr("c", "d").build();
root.append_child(child);
let other_child = Element::builder("child")
.ns("child_ns")
.attr("d", "e")
.attr("xml:lang", "fr")
.build();
.ns("child_ns")
.attr("d", "e")
.attr("xml:lang", "fr")
.build();
root.append_child(other_child);
root.append_text_node("nya");
root
@ -43,7 +41,10 @@ fn build_comment_test_tree() -> Element {
#[test]
fn reader_works() {
let mut reader = Reader::from_str(TEST_STRING);
assert_eq!(Element::from_reader(&mut reader).unwrap(), build_test_tree());
assert_eq!(
Element::from_reader(&mut reader).unwrap(),
build_test_tree()
);
}
#[test]
@ -58,40 +59,38 @@ fn writer_works() {
#[test]
fn writer_escapes_attributes() {
let root = Element::builder("root")
.attr("a", "\"Air\" quotes")
.build();
let root = Element::builder("root").attr("a", "\"Air\" quotes").build();
let mut writer = Vec::new();
{
root.write_to(&mut writer).unwrap();
}
assert_eq!(String::from_utf8(writer).unwrap(),
r#"<?xml version="1.0" encoding="utf-8"?><root a="&quot;Air&quot; quotes"/>"#
assert_eq!(
String::from_utf8(writer).unwrap(),
r#"<?xml version="1.0" encoding="utf-8"?><root a="&quot;Air&quot; quotes"/>"#
);
}
#[test]
fn writer_escapes_text() {
let root = Element::builder("root")
.append("<3")
.build();
let root = Element::builder("root").append("<3").build();
let mut writer = Vec::new();
{
root.write_to(&mut writer).unwrap();
}
assert_eq!(String::from_utf8(writer).unwrap(),
r#"<?xml version="1.0" encoding="utf-8"?><root>&lt;3</root>"#
assert_eq!(
String::from_utf8(writer).unwrap(),
r#"<?xml version="1.0" encoding="utf-8"?><root>&lt;3</root>"#
);
}
#[test]
fn builder_works() {
let elem = Element::builder("a")
.ns("b")
.attr("c", "d")
.append(Element::builder("child"))
.append("e")
.build();
.ns("b")
.attr("c", "d")
.append(Element::builder("child"))
.append("e")
.build();
assert_eq!(elem.name(), "a");
assert_eq!(elem.ns(), Some("b".to_owned()));
assert_eq!(elem.attr("c"), Some("d"));
@ -115,10 +114,22 @@ fn get_child_works() {
let root = build_test_tree();
assert_eq!(root.get_child("child", "inexistent_ns"), None);
assert_eq!(root.get_child("not_a_child", "root_ns"), None);
assert!(root.get_child("child", "root_ns").unwrap().is("child", "root_ns"));
assert!(root.get_child("child", "child_ns").unwrap().is("child", "child_ns"));
assert_eq!(root.get_child("child", "root_ns").unwrap().attr("c"), Some("d"));
assert_eq!(root.get_child("child", "child_ns").unwrap().attr("d"), Some("e"));
assert!(root
.get_child("child", "root_ns")
.unwrap()
.is("child", "root_ns"));
assert!(root
.get_child("child", "child_ns")
.unwrap()
.is("child", "child_ns"));
assert_eq!(
root.get_child("child", "root_ns").unwrap().attr("c"),
Some("d")
);
assert_eq!(
root.get_child("child", "child_ns").unwrap().attr("d"),
Some("e")
);
}
#[test]
@ -130,9 +141,14 @@ fn namespace_propagation_works() {
root.append_child(child);
assert_eq!(root.get_child("child", "root_ns").unwrap().ns(), root.ns());
assert_eq!(root.get_child("child", "root_ns").unwrap()
.get_child("grandchild", "root_ns").unwrap()
.ns(), root.ns());
assert_eq!(
root.get_child("child", "root_ns")
.unwrap()
.get_child("grandchild", "root_ns")
.unwrap()
.ns(),
root.ns()
);
}
#[test]
@ -151,7 +167,13 @@ fn namespace_attributes_works() {
let mut reader = Reader::from_str(TEST_STRING);
let root = Element::from_reader(&mut reader).unwrap();
assert_eq!("en", root.attr("xml:lang").unwrap());
assert_eq!("fr", root.get_child("child", "child_ns").unwrap().attr("xml:lang").unwrap());
assert_eq!(
"fr",
root.get_child("child", "child_ns")
.unwrap()
.attr("xml:lang")
.unwrap()
);
}
#[test]
@ -174,14 +196,20 @@ fn namespace_simple() {
#[test]
fn namespace_prefixed() {
let elem: Element = "<stream:features xmlns:stream='http://etherx.jabber.org/streams'/>"
.parse().unwrap();
.parse()
.unwrap();
assert_eq!(elem.name(), "features");
assert_eq!(elem.ns(), Some("http://etherx.jabber.org/streams".to_owned()));
assert_eq!(
elem.ns(),
Some("http://etherx.jabber.org/streams".to_owned())
);
}
#[test]
fn namespace_inherited_simple() {
let elem: Element = "<stream xmlns='jabber:client'><message/></stream>".parse().unwrap();
let elem: Element = "<stream xmlns='jabber:client'><message/></stream>"
.parse()
.unwrap();
assert_eq!(elem.name(), "stream");
assert_eq!(elem.ns(), Some("jabber:client".to_owned()));
let child = elem.children().next().unwrap();
@ -194,7 +222,10 @@ fn namespace_inherited_prefixed1() {
let elem: Element = "<stream:features xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'><message/></stream:features>"
.parse().unwrap();
assert_eq!(elem.name(), "features");
assert_eq!(elem.ns(), Some("http://etherx.jabber.org/streams".to_owned()));
assert_eq!(
elem.ns(),
Some("http://etherx.jabber.org/streams".to_owned())
);
let child = elem.children().next().unwrap();
assert_eq!(child.name(), "message");
assert_eq!(child.ns(), Some("jabber:client".to_owned()));
@ -205,7 +236,10 @@ fn namespace_inherited_prefixed2() {
let elem: Element = "<stream xmlns='http://etherx.jabber.org/streams' xmlns:jabber='jabber:client'><jabber:message/></stream>"
.parse().unwrap();
assert_eq!(elem.name(), "stream");
assert_eq!(elem.ns(), Some("http://etherx.jabber.org/streams".to_owned()));
assert_eq!(
elem.ns(),
Some("http://etherx.jabber.org/streams".to_owned())
);
let child = elem.children().next().unwrap();
assert_eq!(child.name(), "message");
assert_eq!(child.ns(), Some("jabber:client".to_owned()));
@ -215,7 +249,10 @@ fn namespace_inherited_prefixed2() {
#[test]
fn read_comments() {
let mut reader = Reader::from_str(COMMENT_TEST_STRING);
assert_eq!(Element::from_reader(&mut reader).unwrap(), build_comment_test_tree());
assert_eq!(
Element::from_reader(&mut reader).unwrap(),
build_comment_test_tree()
);
}
#[cfg(feature = "comments")]
@ -233,12 +270,12 @@ fn write_comments() {
fn xml_error() {
match "<a></b>".parse::<Element>() {
Err(crate::error::Error::XmlError(_)) => (),
err => panic!("No or wrong error: {:?}", err)
err => panic!("No or wrong error: {:?}", err),
}
match "<a></".parse::<Element>() {
Err(crate::error::Error::XmlError(_)) => (),
err => panic!("No or wrong error: {:?}", err)
err => panic!("No or wrong error: {:?}", err),
}
}
@ -246,6 +283,6 @@ fn xml_error() {
fn invalid_element_error() {
match "<a:b:c>".parse::<Element>() {
Err(crate::error::Error::InvalidElement) => (),
err => panic!("No or wrong error: {:?}", err)
err => panic!("No or wrong error: {:?}", err),
}
}