2020-03-23 02:08:41 +00:00
|
|
|
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
|
|
|
|
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
2020-05-23 07:49:04 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod passing {
|
|
|
|
use html5ever::rcdom::{Handle, NodeData};
|
2020-03-23 02:08:41 +00:00
|
|
|
|
2021-10-17 07:16:37 +00:00
|
|
|
use monolith::html;
|
2020-06-28 05:36:41 +00:00
|
|
|
|
2020-05-23 07:49:04 +00:00
|
|
|
#[test]
|
2020-11-23 05:12:26 +00:00
|
|
|
fn parent_node_names() {
|
2020-05-23 07:49:04 +00:00
|
|
|
let html = "<!doctype html><html><HEAD></HEAD><body><div><P></P></div></body></html>";
|
2021-10-17 07:16:37 +00:00
|
|
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
2020-05-23 07:49:04 +00:00
|
|
|
let mut count = 0;
|
2020-03-23 02:08:41 +00:00
|
|
|
|
2020-05-23 07:49:04 +00:00
|
|
|
fn test_walk(node: &Handle, i: &mut i8) {
|
|
|
|
*i += 1;
|
|
|
|
|
|
|
|
match &node.data {
|
|
|
|
NodeData::Document => {
|
|
|
|
for child in node.children.borrow().iter() {
|
|
|
|
test_walk(child, &mut *i);
|
|
|
|
}
|
2020-03-23 02:08:41 +00:00
|
|
|
}
|
2020-05-23 07:49:04 +00:00
|
|
|
NodeData::Element { ref name, .. } => {
|
|
|
|
let node_name = name.local.as_ref().to_string();
|
|
|
|
let parent = html::get_parent_node(node);
|
|
|
|
let parent_node_name = html::get_node_name(&parent);
|
|
|
|
if node_name == "head" || node_name == "body" {
|
|
|
|
assert_eq!(parent_node_name, Some("html"));
|
|
|
|
} else if node_name == "div" {
|
|
|
|
assert_eq!(parent_node_name, Some("body"));
|
|
|
|
} else if node_name == "p" {
|
|
|
|
assert_eq!(parent_node_name, Some("div"));
|
|
|
|
}
|
2020-03-23 02:08:41 +00:00
|
|
|
|
2020-05-23 07:49:04 +00:00
|
|
|
for child in node.children.borrow().iter() {
|
|
|
|
test_walk(child, &mut *i);
|
|
|
|
}
|
2020-03-23 02:08:41 +00:00
|
|
|
}
|
2020-05-23 07:49:04 +00:00
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
}
|
2020-03-23 02:08:41 +00:00
|
|
|
|
2020-05-23 07:49:04 +00:00
|
|
|
test_walk(&dom.document, &mut count);
|
2020-03-23 02:08:41 +00:00
|
|
|
|
2020-05-23 07:49:04 +00:00
|
|
|
assert_eq!(count, 7);
|
|
|
|
}
|
2020-03-23 02:08:41 +00:00
|
|
|
}
|