tests/testthat/test-rmd.R

context("R Markdown")

test_that("The chunk header parser works as expected", {

  cases <- list(

    # R Markdown ----
    list(
      input    = "```{r}",
      type     = "md",
      expected = list(engine = "r")
    ),

    list(
      input    = "```{r a-b-c}",
      type     = "md",
      expected = list(engine = "r", label = "a-b-c")
    ),

    list(
      input    = "```{r, a-b-c}",
      type     = "md",
      expected = list(engine = "r", label = "a-b-c")
    ),

    list(
      input    = "```{r, a-b-c, a=1+1}",
      type     = "md",
      expected = list(engine = "r", label = "a-b-c", a = quote(1 + 1))
    ),

    list(
      input    = "```{python}",
      type     = "md",
      expected = list(engine = "python")
    ),

    # Sweave ----
    list(
      input = "<<a-b-c>>=",
      type  = "rnw",
      expected = list(engine = "r", label = "a-b-c")
    ),

    list(
      input = "<<a-b-c, a=1, b=2>>=",
      type  = "rnw",
      expected = list(engine = "r", label = "a-b-c", a = 1, b = 2)
    )

  )

  for (case in cases) {
    output <- renv_dependencies_discover_parse_params(case$input, case$type)
    expect_same_elements(output, case$expected)
  }

})
slopp/renv documentation built on July 6, 2019, 12:08 a.m.