use html_streaming_editor::*; const HTML_INPUT: &str = r#"

Title

Some first text

Some more text, even with an

Third text of HTML, but no CSS

"#; #[test] fn append_to_first_p_content() -> Result<(), StreamingEditorError> { let command = "EXTRACT-ELEMENT{#first-para} | APPEND-COMMENT{'followed by a comment'}"; let mut input = Box::new(HTML_INPUT.as_bytes()); let hse = HtmlStreamingEditor::new(&mut input); let result = hse.run(command)?; let result_string = result .iter() .map(|n| n.outer_html()) .collect::>() .join(""); assert_eq!( result_string, String::from(r#"

Some first text

"#) ); Ok(()) } #[test] fn append_to_ul() -> Result<(), StreamingEditorError> { let command = "EXTRACT-ELEMENT{ul} | APPEND-COMMENT{'Foo'}"; let mut input = Box::new(HTML_INPUT.as_bytes()); let hse = HtmlStreamingEditor::new(&mut input); let result = hse.run(command)?; let result_string = result .iter() .map(|n| n.outer_html()) .collect::>() .join(""); assert_eq!( result_string, String::from( r#""# ) ); Ok(()) } #[test] fn append_double_dash_will_be_escaped() -> Result<(), StreamingEditorError> { let command = "EXTRACT-ELEMENT{#first-para} | APPEND-COMMENT{'Actually -- is illegal in comments'}"; let mut input = Box::new(HTML_INPUT.as_bytes()); let hse = HtmlStreamingEditor::new(&mut input); let result = hse.run(command)?; let result_string = result .iter() .map(|n| n.outer_html()) .collect::>() .join(""); assert_eq!( result_string, String::from( r#"

Some first text

"# ) ); Ok(()) } #[test] fn append_ul_id_as_comment_to_first_para() -> Result<(), StreamingEditorError> { let command = "FOR-EACH{#first-para ↦ APPEND-COMMENT{ QUERY-PARENT{ul} | GET-ATTR{id} } }"; let mut input = Box::new(HTML_INPUT.as_bytes()); let hse = HtmlStreamingEditor::new(&mut input); let result = hse.run(command)?; let result_string = result .iter() .map(|n| n.outer_html()) .collect::>() .join(""); assert_eq!( result_string, String::from( r#"

Title

Some first text

Some more text, even with an

Third text of HTML, but no CSS

  • 1
  • 2
  • 3
"# ) ); Ok(()) }