5 assert_eq!(HtmlWithLimit::new(0).finish(), "");
6 assert_eq!(HtmlWithLimit::new(60).finish(), "");
11 let mut buf = HtmlWithLimit::new(60);
17 assert_eq!(buf.finish(), "Hello <em>world</em>!");
22 let mut buf = HtmlWithLimit::new(60);
25 assert_eq!(buf.finish(), "Hello world!");
30 let mut buf = HtmlWithLimit::new(0);
36 assert_eq!(buf.finish(), "");
41 let mut buf = HtmlWithLimit::new(12);
47 assert_eq!(buf.finish(), "Hello <em>world</em>!");
51 fn multiple_nested_tags() {
52 let mut buf = HtmlWithLimit::new(60);
54 buf.push("This is a ");
56 buf.push("paragraph");
57 buf.open_tag("strong");
62 assert_eq!(buf.finish(), "<p>This is a <em>paragraph<strong>!</strong></em></p>");
66 fn forgot_to_close_tags() {
67 let mut buf = HtmlWithLimit::new(60);
69 buf.push("This is a ");
71 buf.push("paragraph");
72 buf.open_tag("strong");
74 assert_eq!(buf.finish(), "<p>This is a <em>paragraph<strong>!</strong></em></p>");
79 let mut buf = HtmlWithLimit::new(20);
81 (0..10).try_for_each(|n| {
82 buf.open_tag("strong");
84 buf.push(&n.to_string())?;
92 <strong>word#0</strong>\
93 <strong>word#1</strong>\
94 <strong>word#2</strong>\
100 fn quickly_past_the_limit() {
101 let mut buf = HtmlWithLimit::new(6);
105 // intentionally not closing <p> before finishing
106 assert_eq!(buf.finish(), "<p>Hello</p>");
110 fn close_too_many() {
111 let mut buf = HtmlWithLimit::new(60);
115 // This call does not panic because there are valid cases
116 // where `close_tag()` is called with no tags left to close.
117 // So `close_tag()` does nothing in this case.
119 assert_eq!(buf.finish(), "<p>Hello</p>");