compact_str/features/
markup.rs1#[cfg(test)]
2use alloc::string::String;
3
4use markup::Render;
5
6use crate::CompactString;
7
8#[cfg_attr(docsrs, doc(cfg(feature = "markup")))]
9impl Render for CompactString {
10 #[inline]
11 fn render(&self, writer: &mut impl core::fmt::Write) -> core::fmt::Result {
12 self.as_str().render(writer)
13 }
14}
15
16#[cfg(test)]
17#[test]
18fn test_markup() {
19 const TEXT: &str = "<script>alert('Hello, world!')</script>";
20
21 markup::define!(Template<M: Render>(msg: M) {
22 textarea { @msg }
23 });
24
25 let compact = Template {
26 msg: CompactString::from(TEXT),
27 };
28 let control = Template {
29 msg: String::from(TEXT),
30 };
31 assert_eq!(
32 compact.to_string(),
33 "<textarea><script>alert('Hello, world!')</script></textarea>",
34 );
35 assert_eq!(
36 control.to_string(),
37 "<textarea><script>alert('Hello, world!')</script></textarea>",
38 );
39}