use tidyrs::embed::Verbatim; use tidyrs::html::{Settings, format}; fn html(text: &str) -> String { let settings = Settings { filepath: Some("index.html".into()), ..Settings::default() }; format(text, &settings, &mut Verbatim).unwrap() } #[test] fn formats_a_document() { assert_eq!( html( "Hi

Hello world

" ), "\n\n \n Hi\n \n \n

Hello world

\n \n\n" ); } #[test] fn prints_attributes() { assert_eq!( html( "
\n" ), "\n \n\n" ); } #[test] fn prints_quotes_and_entities() { assert_eq!( html( "
\n" ), "\n \n\n" ); } #[test] fn prints_borrowed_markers_once() { assert_eq!(html("a"), "a\n"); assert_eq!(html("


"), "


\n"); assert_eq!( html("ac"), "ac\n" ); } #[test] fn leaves_attributes_without_embedded_formatting() { let settings = Settings { format_embedded: false, ..Settings::default() }; assert_eq!( format( "

", &settings, &mut Verbatim ) .unwrap(), "\n

\n" ); } #[test] fn takes_another_ignore_directive() { let settings = Settings { ignore: "tidy-ignore".into(), ..Settings::default() }; let text = "\n

x

\n\n

x

\n\n

x

\n"; assert_eq!( format(text, &settings, &mut Verbatim).unwrap(), "\n

x

\n\n

x

\n\n

x

\n" ); } #[test] fn tells_the_host_whether_a_script_is_a_module() { let mut modules = Vec::new(); let mut hook = |request: tidyrs::embed::Request<'_>| { modules.push(request.module); Some("x = ``".to_owned()) }; let text = "\n\n\n"; let printed = format(text, &Settings::default(), &mut hook).unwrap(); assert_eq!(modules, [false, true, true]); assert_eq!(printed.matches(r"x = `<\/SCRIPT>`").count(), 3, "{printed}"); }