use node_html_parser::HTMLElement;
#[test]
fn issue_112_html_element_id_ctor_and_attr_sync() {
let el = HTMLElement::new(Some("div".to_string()), String::new(), vec![], false, false);
assert_eq!(el.id, "");
assert!(el.get_attr("id").is_none());
assert_eq!(el.to_string(), "<div></div>");
let el2 = HTMLElement::new(
Some("div".to_string()),
"id=\"id\"".to_string(),
vec![("id".to_string(), "id".to_string())],
false,
false,
);
assert_eq!(el2.id, "id");
assert_eq!(el2.get_attr("id"), Some("id"));
assert_eq!(el2.to_string(), "<div id=\"id\"></div>");
}
#[test]
fn issue_112_remove_attribute_updates_id() {
let html = "<div id=\"id\"></div>";
let root = node_html_parser::parse(html);
let el = root.first_element_child().unwrap();
assert_eq!(el.id, "id");
assert_eq!(el.get_attr("id"), Some("id"));
let mut cloned = el.clone_shallow();
cloned.remove_id();
assert_eq!(cloned.id, "");
assert!(cloned.get_attr("id").is_none());
assert_eq!(cloned.to_string(), "<div></div>");
}
#[test]
fn issue_112_set_attribute_updates_id() {
let html = "<div></div>";
let root = node_html_parser::parse(html);
let el = root.first_element_child().unwrap();
assert_eq!(el.id, "");
assert!(el.get_attr("id").is_none());
let mut cloned = el.clone_shallow();
cloned.set_id("id");
assert_eq!(cloned.id, "id");
assert_eq!(cloned.get_attr("id"), Some("id"));
assert_eq!(cloned.to_string(), "<div id=\"id\"></div>");
}