minidom: clarify meaning of Element.name (being the local name)

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2020-03-28 16:41:48 +01:00
parent 171e7f1f34
commit 40b92d64e2

View file

@ -207,8 +207,7 @@ impl Element {
)
}
/// Returns a reference to the name of this element.
// TODO: rename local_name
/// Returns a reference to the local name of this element (that is, without a possible prefix).
pub fn name(&self) -> &str {
&self.name
}
@ -1079,6 +1078,18 @@ mod tests {
assert_eq!(elem.unwrap(), elem2);
}
#[test]
fn test_from_reader_split_prefix() {
let xml = "<foo:bar xmlns:foo='ns1'/>";
let mut reader = EventReader::from_str(xml);
let elem = Element::from_reader(&mut reader).unwrap();
assert_eq!(elem.name(), String::from("bar"));
assert_eq!(elem.ns(), String::from("ns1"));
// Ensure the prefix is properly added to the store
assert_eq!(elem.prefixes.get(&String::from("ns1")), Some(Some(String::from("foo"))));
}
#[test]
fn parses_spectest_xml() {
// From: https://gitlab.com/lumi/minidom-rs/issues/8