use std::borrow::Cow;
use fhp_core::tag::Tag;
#[derive(Clone, Debug, PartialEq)]
pub enum Token<'a> {
OpenTag {
tag: Tag,
name: Cow<'a, str>,
attributes: Vec<Attribute<'a>>,
self_closing: bool,
},
CloseTag {
tag: Tag,
name: Cow<'a, str>,
},
Text {
content: Cow<'a, str>,
},
Comment {
content: Cow<'a, str>,
},
Doctype {
content: Cow<'a, str>,
},
CData {
content: Cow<'a, str>,
},
}
#[derive(Clone, Debug, PartialEq)]
pub struct Attribute<'a> {
pub name: Cow<'a, str>,
pub value: Option<Cow<'a, str>>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn token_clone_and_debug() {
let tok = Token::Text {
content: Cow::Borrowed("hello"),
};
let tok2 = tok.clone();
assert_eq!(tok, tok2);
assert!(format!("{tok:?}").contains("hello"));
}
#[test]
fn attribute_with_value() {
let attr = Attribute {
name: Cow::Borrowed("class"),
value: Some(Cow::Borrowed("foo")),
};
assert_eq!(attr.name.as_ref(), "class");
assert_eq!(attr.value.as_deref(), Some("foo"));
}
#[test]
fn boolean_attribute() {
let attr = Attribute {
name: Cow::Borrowed("disabled"),
value: None,
};
assert!(attr.value.is_none());
}
}