-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also look for templates in man/roxygen/templates
Fixes #888
- Loading branch information
Showing
7 changed files
with
30 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#' <%= x %> | ||
#' @param <%= y %> <%= z %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,38 @@ | ||
context("Rd: template") | ||
|
||
test_that("template_find finds files with .r and .R extension, and fails to find missing files", { | ||
my.tempdir <- "." | ||
my.mandir <- file.path(my.tempdir, "man-roxygen") | ||
my.ucase <- file.path(my.mandir, "UCase.R") | ||
my.regex <- file.path(my.mandir, "reg.ex.R") | ||
my.lcase <- file.path(my.mandir, "lcase.r") | ||
test_that("can find template from name", { | ||
base <- test_path("templates/") | ||
|
||
expect_equal(template_find(my.tempdir, "UCase"), my.ucase) | ||
expect_error(template_find(my.tempdir, "Case")) | ||
expect_error(template_find(my.tempdir, "UCas")) | ||
expect_equal(template_find(my.tempdir, "reg.ex"), my.regex) | ||
expect_error(template_find(my.tempdir, "reggex")) | ||
expect_error(template_find(my.tempdir, "nada")) | ||
expect_equal( | ||
template_find(base, "UCase"), | ||
file.path(base, "man-roxygen", "UCase.R") | ||
) | ||
|
||
# On case-insentive file systems, will find upper case version first | ||
expect_equal(tolower(template_find(my.tempdir, "lcase")), tolower(my.lcase)) | ||
}) | ||
expect_equal( | ||
tolower(template_find(base, "lcase")), | ||
tolower(file.path(base, "man-roxygen", "lcase.r")) | ||
) | ||
|
||
test_that("templates replace variables with their values", { | ||
out <- roc_proc_text(rd_roclet(), " | ||
#' @template values | ||
#' @templateVar x a | ||
#' @templateVar y b | ||
#' @templateVar z c | ||
x <- 10")[[1]] | ||
expect_equal( | ||
template_find(base, "new-path"), | ||
file.path(base, "man" , "roxygen", "templates", "new-path.R") | ||
) | ||
|
||
expect_equal(get_tag(out, "title")$values, "a") | ||
expect_equal(get_tag(out, "param")$values, c(b = "c")) | ||
expect_error( | ||
template_find(base, "missing"), | ||
"Can't find template" | ||
) | ||
}) | ||
|
||
test_that("allow empty line after @template", { | ||
test_that("templates replace variables with their values", { | ||
out <- roc_proc_text(rd_roclet(), " | ||
#' @template values | ||
#' | ||
#' @templateVar x a | ||
#' @templateVar y b | ||
#' @templateVar z c | ||
x <- 10")[[1]] | ||
|
||
expect_equal(get_tag(out, "title")$values, "a") | ||
expect_equal(get_tag(out, "param")$values, c(b = "c")) | ||
}) |