pub(crate) mod part1;
pub(crate) mod part2;
pub(crate) mod part3;
pub use part1::PART1;
pub use part2::PART2;
pub use part3::PART3;
pub fn lookup_html<S: AsRef<str>>(pattern: S) -> Option<(&'static str, &'static str)> {
let pattern = pattern.as_ref();
part1::PART1
.get(pattern)
.or_else(|| part2::PART2.get(pattern))
.or_else(|| part3::PART3.get(pattern))
.copied()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_html_entities() {
assert_eq!(
lookup_html(" "),
Some(("\u{00A0}", "html named character reference"))
);
assert_eq!(
lookup_html("©"),
Some(("\u{00A9}", "html named character reference"))
);
assert_eq!(
lookup_html("α"),
Some(("\u{03B1}", "html named character reference"))
);
}
#[test]
fn test_no_ampersand_not_supported() {
assert_eq!(lookup_html("nbsp;"), None);
assert_eq!(lookup_html("copy;"), None);
assert_eq!(lookup_html("alpha;"), None);
}
#[test]
fn test_improperly_formatted_entities() {
assert_eq!(lookup_html(" "), None);
assert_eq!(lookup_html("©"), None);
}
#[test]
fn test_common_entities() {
assert_eq!(
lookup_html("<"),
Some(("\u{003C}", "html named character reference"))
); assert_eq!(
lookup_html(">"),
Some(("\u{003E}", "html named character reference"))
); assert_eq!(
lookup_html("&"),
Some(("\u{0026}", "html named character reference"))
); assert_eq!(
lookup_html("""),
Some(("\u{0022}", "html named character reference"))
); }
}