2020-11-23 06:12:26 +01:00
|
|
|
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
|
|
|
|
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod passing {
|
|
|
|
use html5ever::rcdom::{Handle, NodeData};
|
|
|
|
|
|
|
|
use crate::html;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn div_two_style_attributes() {
|
|
|
|
let html = "<!doctype html><html><head></head><body><DIV STYLE=\"color: blue;\" style=\"display: none;\"></div></body></html>";
|
2021-06-08 14:30:15 +02:00
|
|
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
2020-11-23 06:12:26 +01:00
|
|
|
let mut count = 0;
|
|
|
|
|
|
|
|
fn test_walk(node: &Handle, i: &mut i8) {
|
|
|
|
*i += 1;
|
|
|
|
|
|
|
|
match &node.data {
|
|
|
|
NodeData::Document => {
|
|
|
|
// Dig deeper
|
|
|
|
for child in node.children.borrow().iter() {
|
|
|
|
test_walk(child, &mut *i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NodeData::Element { ref name, .. } => {
|
|
|
|
let node_name = name.local.as_ref().to_string();
|
|
|
|
|
|
|
|
if node_name == "body" {
|
|
|
|
assert_eq!(html::get_node_attr(node, "class"), None);
|
|
|
|
} else if node_name == "div" {
|
|
|
|
assert_eq!(
|
|
|
|
html::get_node_attr(node, "style"),
|
|
|
|
Some(str!("color: blue;"))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
for child in node.children.borrow().iter() {
|
|
|
|
test_walk(child, &mut *i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
test_walk(&dom.document, &mut count);
|
|
|
|
|
|
|
|
assert_eq!(count, 6);
|
|
|
|
}
|
|
|
|
}
|