Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rundel committed Aug 5, 2024
1 parent 8beb30a commit 2bf2897
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 31 deletions.
15 changes: 12 additions & 3 deletions tests/testthat/test-parse-fenced_divs.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ And another.
parse_rmd(ex1),
rmd_ast(
rmd_fenced_div_open(c("#special",".sidebar")),
rmd_markdown("Here is a paragraph.","","And another."),
rmd_markdown(
rmd_markdown_line("Here is a paragraph."),
rmd_markdown_line(""),
rmd_markdown_line("And another.")
),
rmd_fenced_div_close()
)
)
Expand All @@ -191,9 +195,14 @@ This is a warning within a warning.
parse_rmd(ex2),
rmd_ast(
rmd_fenced_div_open(".Warning"),
rmd_markdown("This is a warning.", ""),
rmd_markdown(
rmd_markdown_line("This is a warning."),
rmd_markdown_line("")
),
rmd_fenced_div_open(".Danger"),
rmd_markdown("This is a warning within a warning."),
rmd_markdown(
rmd_markdown_line("This is a warning within a warning.")
),
rmd_fenced_div_close(),
rmd_fenced_div_close()
)
Expand Down
23 changes: 17 additions & 6 deletions tests/testthat/test-parse-markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,50 @@ test_that("markdown", {

expect_identical(
check_markdown_parser("test\n"),
rmd_markdown("test")
rmd_markdown(
rmd_markdown_line("test")
)
)

expect_identical(
check_markdown_parser("test\ntest\n"),
rmd_markdown("test", "test")
rmd_markdown(
rmd_markdown_line("test"),
rmd_markdown_line("test")
)
)

expect_identical(
check_markdown_parser("`r 1+1`\n"),
rmd_markdown(
rmd_inline_code(engine = "r", code="1+1")
rmd_markdown_line(
rmd_inline_code(engine = "r", code="1+1")
)
)
)

expect_identical(
check_markdown_parser("`{r} 1+1`\n"),
rmd_markdown(
rmd_inline_code(engine = "r", code="1+1")
rmd_markdown_line(
rmd_inline_code(engine = "r", code="1+1")
)
)
)

expect_identical(
check_markdown_parser("``r 1+1``\n"),
rmd_markdown(
list("`", rmd_inline_code(engine = "r", code="1+1"), "`")
rmd_markdown_line(
"`", rmd_inline_code(engine = "r", code="1+1"), "`"
)
)
)

expect_identical(
check_markdown_parser("``{r} 1+1``\n"),
rmd_markdown(
list("`", rmd_inline_code(engine = "r", code="1+1"), "`")
rmd_markdown_line("`", rmd_inline_code(engine = "r", code="1+1"), "`")
)
)
})
Expand Down
21 changes: 17 additions & 4 deletions tests/testthat/test-parse-yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,37 @@ test_that("Pandoc - yaml metadata block", { # See https://pandoc.org/MANUAL.html
expect_equal(
parse_rmd("---\n\n...\n"),
rmd_ast(
rmd_markdown("---","","...")
rmd_markdown(
rmd_markdown_line("---"),
rmd_markdown_line(""),
rmd_markdown_line("...")
)
)
)

expect_equal(
parse_rmd("---\n\n---\n---\n...\n"),
rmd_ast(
rmd_markdown("---",""),
rmd_markdown(
rmd_markdown_line("---"),
rmd_markdown_line("")
),
rmd_yaml(),
rmd_markdown("...")
rmd_markdown(
rmd_markdown_line("...")
)
)
)

expect_equal(
parse_rmd("---\n---\n---\n\n...\n"),
rmd_ast(
rmd_yaml(),
rmd_markdown("---","","...")
rmd_markdown(
rmd_markdown_line("---"),
rmd_markdown_line(""),
rmd_markdown_line("...")
)
)
)
})
8 changes: 4 additions & 4 deletions tests/testthat/test-parse-yaml_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ test_that("parse full document with yaml options", {
title = "Using dash options in YAML options header"
),
rmd_markdown(
"In Quarto, it is recommended to use YAML options format with dash in option name instead of dot. In knitr 1.44, any chunk option with dash will be transformed to its dot counterpart. This is because knitr is responsible for engine option parsing in Quarto. ",
"",
"This document checks that YAML options are parsed correctly and that dash option are correctly converted when provided in YAML. ",
""
rmd_markdown_line("In Quarto, it is recommended to use YAML options format with dash in option name instead of dot. In knitr 1.44, any chunk option with dash will be transformed to its dot counterpart. This is because knitr is responsible for engine option parsing in Quarto. "),
rmd_markdown_line(""),
rmd_markdown_line("This document checks that YAML options are parsed correctly and that dash option are correctly converted when provided in YAML. "),
rmd_markdown_line("")
),
rmd_chunk(
engine = "r",
Expand Down
30 changes: 16 additions & 14 deletions tests/testthat/test-parse_rmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ test_that("minimal.Rmd", {

expected_ast = rmd_ast(
rmd_yaml(
'title: "Minimal"',
'author: "Colin Rundel"',
'date: "7/21/2020"',
'output: html_document',
parse = TRUE
title = "Minimal",
author = "Colin Rundel",
date = "7/21/2020",
output = "html_document"
),
rmd_heading("Setup", 1),
rmd_chunk(
Expand All @@ -17,12 +16,12 @@ test_that("minimal.Rmd", {
rmd_heading("Content", 1),
rmd_heading("R Markdown", 2),
rmd_markdown(
'This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, ',
'PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.',
'',
'When you click the **Knit** button a document will be generated that includes both content as well ',
'as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:',
''
rmd_markdown_line('This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, '),
rmd_markdown_line('PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.'),
rmd_markdown_line(''),
rmd_markdown_line('When you click the **Knit** button a document will be generated that includes both content as well '),
rmd_markdown_line('as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:'),
rmd_markdown_line('')
),
rmd_chunk(
name = "cars", code = "summary(cars)"
Expand All @@ -31,14 +30,17 @@ test_that("minimal.Rmd", {
name = "unnamed-chunk-1", code = "knitr::knit_patterns$get()"
),
rmd_heading("Including Plots", 2),
rmd_markdown("You can also embed plots, for example:", ""),
rmd_markdown(
rmd_markdown_line("You can also embed plots, for example:"),
rmd_markdown_line("")
),
rmd_chunk(
name = "pressure", options = list(echo = "FALSE"),
code = "plot(pressure)"
),
rmd_markdown(
"Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code ",
"that generated the plot."
rmd_markdown_line("Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code "),
rmd_markdown_line("that generated the plot.")
)
)

Expand Down

0 comments on commit 2bf2897

Please sign in to comment.