");
let div = document.nth(3).unwrap();
assert_eq!(div.name(), Some("div"));
assert_eq!(div.html(), r#"
"#);
}
test "Node::inner_html()" {
assert_eq!(html.inner_html(), "\
foo
baz\
");
assert_eq!(head.inner_html(), "");
assert_eq!(foo.inner_html(), "");
assert_eq!(quux.inner_html(), "");
assert_eq!(comment.inner_html(), "");
}
test "Node::children()" {
let mut children = html.children();
assert_eq!(children.next().unwrap().name(), Some("head"));
assert_eq!(children.next().unwrap().name(), Some("body"));
assert_eq!(children.next(), None);
assert_eq!(body.children().count(), 2);
assert_eq!(baz.children().count(), 0);
assert_eq!(quux.children().count(), 1);
}
test "Node::descendants()" {
use select::predicate::*;
let document = Document::from(include_str!("fixtures/struct.Vec.html"));
for i in 0..document.nodes.len() {
let node = document.nth(i).unwrap();
let actual = node.descendants().map(|node| node.index()).collect::
>();
let expected = node.find(Any).map(|node| node.index()).collect::>();
assert_eq!(actual, expected);
}
}
test "Node::attrs()" {
let mut attrs = quux.attrs();
assert_eq!(attrs.next(), Some(("class", "another-thing")));
assert_eq!(attrs.next(), None);
}
test "std::fmt::Debug for Node" {
assert_eq!(format!("{:?}", bar).replace(' ', ""), r#"Element {
name: "bar",
attrs: [],
children: [
Text("baz"),
Element {
name: "quux",
attrs: [("class", "another-thing")],
children: [Comment("comment")]
}
]}"#.replace(['\n', ' '], ""));
assert_eq!(format!("{:?}", baz), "Text(\"baz\")");
assert_eq!(format!("{:?}", quux).replace(' ', ""), r#"Element {
name: "quux",
attrs: [("class", "another-thing")],
children: [Comment("comment")]
}"#.replace(['\n', ' '], ""));
assert_eq!(format!("{:?}", comment), "Comment(\"comment\")");
}
test "Children::into_selection()" {
let document = Document::from(include_str!("fixtures/struct.Vec.html"));
for i in 0..document.nodes.len() {
let node = document.nth(i).unwrap();
let actual = node.children().into_selection().iter().map(|node| {
node.index()
}).collect::>();
let expected = node.children().map(|node| node.index()).collect::>();
assert_eq!(actual, expected);
}
}
// https://github.com/utkarshkukreti/select.rs/pull/38
test "issue #38" {
{
use select::predicate::*;
let _bar = {
let body = html.find(Name("body")).next().unwrap();
body.find(Name("bar")).next().unwrap()
};
}
}
}
}