2020-03-23 03:08:41 +01:00
|
|
|
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
|
|
|
|
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod passing {
|
|
|
|
use html5ever::rcdom::{Handle, NodeData};
|
2020-03-23 03:08:41 +01:00
|
|
|
|
2020-06-28 07:36:41 +02:00
|
|
|
use crate::html;
|
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
#[test]
|
2020-11-23 06:12:26 +01:00
|
|
|
fn parent_node_names() {
|
2020-05-23 09:49:04 +02:00
|
|
|
let html = "<!doctype html><html><HEAD></HEAD><body><div><P></P></div></body></html>";
|
2021-06-08 14:30:15 +02:00
|
|
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
2020-05-23 09:49:04 +02:00
|
|
|
let mut count = 0;
|
2020-03-23 03:08:41 +01:00
|
|
|
|
2020-05-23 09:49:04 +02: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 03:08:41 +01:00
|
|
|
}
|
2020-05-23 09:49:04 +02: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 03:08:41 +01:00
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
for child in node.children.borrow().iter() {
|
|
|
|
test_walk(child, &mut *i);
|
|
|
|
}
|
2020-03-23 03:08:41 +01:00
|
|
|
}
|
2020-05-23 09:49:04 +02:00
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
}
|
2020-03-23 03:08:41 +01:00
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
test_walk(&dom.document, &mut count);
|
2020-03-23 03:08:41 +01:00
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
assert_eq!(count, 7);
|
|
|
|
}
|
2020-03-23 03:08:41 +01:00
|
|
|
}
|