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 prepend_to_first_p_content() -> Result<(), StreamingEditorError> { let command = "EXTRACT-ELEMENT{#first-para} | PREPEND-TEXT-CONTENT{'... expanded by other text'}"; 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#"

... expanded by other textSome first text

"#) ); Ok(()) } #[test] fn prepend_escape_needing_content() -> Result<(), StreamingEditorError> { let command = "EXTRACT-ELEMENT{#first-para} | PREPEND-TEXT-CONTENT{' is > others < & you never know which'}"; 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#"

is > others < & you never know whichSome first text

"# ) ); Ok(()) } #[test] fn prepend_ul_id_as_text_to_first_para() -> Result<(), StreamingEditorError> { let command = "FOR-EACH{#first-para ↦ PREPEND-TEXT-CONTENT{' and ul-id is: '} | PREPEND-TEXT-CONTENT{ 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

list and ul-id is: Some first text

Some more text, even with an

Third text of HTML, but no CSS

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