use anyhow::Result; use asciidoctrine::{self, *}; use clap::Parser; use pretty_assertions::assert_eq; use std::io::BufWriter; #[test] fn bullet_list_with_dashes() -> Result<()> { let content = r#" - This - is - a - list -- with subpoints --- and deeper ---- nested subpoints - Next normal point "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#" "# ); Ok(()) } #[test] fn bullet_list() -> Result<()> { let content = r#" * This * is * a * list ** with subpoints *** and deeper **** nested subpoints * Next normal point "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#" "# ); Ok(()) } #[test] fn collapsible_blocks() -> Result<()> { let content = r#" [%collapsible] ==== Additional Information, that will only be shown on demand. ==== "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"
Details

Additional Information, that will only be shown on demand.

"# ); Ok(()) } #[test] fn collapsible_blocks_open() -> Result<()> { let content = r#" [%collapsible%open] ==== This Information is visible by default. ==== "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"
Details

This Information is visible by default.

"# ); Ok(()) } #[test] fn formated_table() -> Result<()> { let content = r#" [cols="1,a"] |=== | Here inline *markup* _text_ is rendered specially But paragraphs * or ** Lists ** are not handled as such | In this cell *markup* _text_ is handeled specially We can even have multiple paragraphs * List ** with ** multiple * entries |=== "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"

Here inline markup text is rendered specially But paragraphs * or ** Lists ** are not handled as such

In this cell markup text is handeled specially

We can even have multiple paragraphs

  • List

    • with

    • multiple

  • entries

"# ); Ok(()) } #[test] fn atx_headers() -> Result<()> { let content = r#" = This is a header == This is a subheader === This is a subsubheader ==== This is a subsubsubheader "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"

This is a header

This is a subheader

This is a subsubheader

This is a subsubsubheader

"# ); Ok(()) } #[test] fn setext_headers() -> Result<()> { let content = r#" This is a header ================ This is a subheader ------------------- This is a subsubheader ~~~~~~~~~~~~~~~~~~~~~~ This is a subsubsubheader ^^^^^^^^^^^^^^^^^^^^^^^^^ "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"

This is a header

This is a subheader

This is a subsubheader

This is a subsubsubheader

"# ); Ok(()) } #[test] fn inline_bold() -> Result<()> { let content = r#" Some text is *bold*. "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"

Some text is bold.

"# ); Ok(()) } #[test] fn inline_italic() -> Result<()> { let content = r#" Some text is _italic_. "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"

Some text is italic.

"# ); Ok(()) } #[test] fn inline_monospaced() -> Result<()> { let content = r#" Some text is `monospaced`. "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"

Some text is monospaced.

"# ); Ok(()) } #[test] fn numbered_list() -> Result<()> { let content = r#" . This . is . a .. nested . numbered list "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"
  1. This

  2. is

  3. a

    1. nested

  4. numbered list

"# ); Ok(()) } #[test] fn simple_table() -> Result<()> { let content = r#" |=== | Col1 | Col2 | Cel1 | Cel2 | Cel3 | Cel4 |=== "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"

Col1

Col2

Cel1

Cel2

Cel3

Cel4

"# ); Ok(()) } #[test] fn sourcecode_blocks() -> Result<()> { let content = r#" [source, bash] ---- echo "hello world!" ---- [source, bash] .... echo "hello world!" .... "#; let reader = AsciidocReader::new(); let opts = options::Opts::parse_from(vec!["asciidoctrine", "--template", "-"]); let mut env = util::Env::Cache(util::Cache::new()); let ast = reader.parse(content, &opts, &mut env)?; let mut buf = BufWriter::new(Vec::new()); let mut writer = HtmlWriter::new(); writer.write(ast, &opts, &mut buf)?; let output = String::from_utf8(buf.into_inner()?)?; assert_eq!( output, r#"
echo "hello world!"
echo "hello world!"
"# ); Ok(()) }