tests/testthat/test-rd-section.R

test_that("warn if forgotton colom", {
  expect_warning(
    roc_proc_text(rd_roclet(), "
      #' Foo
      #'
      #' @section Haz dox
      #' Here.
      #' There
      foo <- function(x = '%') x
    "),
    "Section title spans multiple lines"
  )
})

test_that("@section-s with identical titles are merged", {
  out <- roc_proc_text(rd_roclet(), "
    #' Foo
    #'
    #' @section Haz dox: Here.
    #'
    #' @section TL: DR.
    foo <- function(x = '%') x

    #' @rdname foo
    #' @section RT: FM.
    #' @section Haz dox:
    #'   Got news.
    bar <- function(y = '%') y
  ")[[1]]

  expect_equal(
    out$get_section("section"),
    rd_section_section(
      c("Haz dox", "TL", "RT"),
      c(" Here.\n\n\n  Got news.", " DR.", " FM.")
    )
  )
})

test_that("@section-s with different titles are kept as they are", {
  out <- roc_proc_text(rd_roclet(), "
    #' Foo
    #'
    #' @section A: 1
    #' @section B: 2
    foo <- function(x) x

    #' @rdname foo
    #' @section C: 3
    bar <- function(x) x
  ")[[1]]

  expect_equal(
    out$get_section("section"),
    rd_section_section(LETTERS[1:3], c(" 1", " 2", " 3"))
  )
})

Try the roxygen2 package in your browser

Any scripts or data that you put into this service are public.

roxygen2 documentation built on Sept. 8, 2021, 9:08 a.m.