use bytes::BytesMut; use rstml_component::{write_html, HtmlFormatter}; macro_rules! assert_html_eq { ($expected:expr, $($rest:tt)*) => { let mut buffer = BytesMut::new(); let mut formatter = HtmlFormatter::new(&mut buffer); write_html!(formatter, $($rest)*).expect("failed to write html"); let raw = buffer.as_ref(); let as_str = std::str::from_utf8(raw).expect("invalid utf-8"); assert_eq!(as_str, $expected); }; } #[test] fn empty() { assert_html_eq!("",); } #[test] fn empty_div() { assert_html_eq!("
",
); assert_html_eq!("
",
); } #[test] fn empty_div_with_attributes() { assert_html_eq!("
",
); } #[test] fn dynamic_attributes() { let attributes = ("class", "test"); assert_html_eq!("
",
); } #[test] fn doctype() { assert_html_eq!("", ); } #[test] fn fragment() { assert_html_eq!("
", <>
); } #[test] fn children() { assert_html_eq!("
test
",
test
); assert_html_eq!("
test
",
"test"
); } #[test] fn kitchen_sink() { let title = "Hello"; let attribute = "world"; let children = "I have in me"; let expected = r#" Hello
1
Hello world with spaces
3
world


I have <html> in me
"# .trim() .lines() .map(|l| l.trim()) .collect::(); assert_html_eq!( expected, {title}
<>
"1"
Hello world with spaces
"3"
{attribute}
//


{children}
); }