Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow roxygen comments in object to be documented #397

Merged
merged 4 commits into from
Oct 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
output. `@rawNamespace` allows you to insert literal text in your namespace:
this can be useful for conditional imports (#385).

* The contents of documented functions are now also parsed for tags. This allows,
e.g., documenting a parameter's type close to where this type is checked,
or documenting implementation details close to the source, and simplifies
future extensions such as the documentation of R6 classes (#397, @krlmlr).

* `register.preref.parser()` and `register.preref.parsers()` have been
deprecated - please use `register_tags()` instead.

Expand Down
17 changes: 4 additions & 13 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ comments <- function(refs) {
# first_line, first_byte, last_line, last_byte
com <- vector("list", length(refs))
for(i in seq_along(refs)) {
# Comments begin after last line of last block, and continue to
# first line of this block
# Comments begin after last line of last block, and this block is included
# so that it can be parsed for additional comments
if (i == 1) {
first_byte <- 1
first_line <- 1
Expand All @@ -56,17 +56,8 @@ comments <- function(refs) {
first_line <- refs[[i - 1]][3]
}

last_line <- refs[[i]][1]
last_byte <- refs[[i]][2] - 1
if (last_byte == 0) {
if (last_line == 1) {
last_byte <- 1
last_line <- 1
} else {
last_line <- last_line - 1
last_byte <- 1e3
}
}
last_line <- refs[[i]][3]
last_byte <- refs[[i]][4]

lloc <- c(first_line, first_byte, last_line, last_byte)
com[[i]] <- srcref(srcfile, lloc)
Expand Down
34 changes: 34 additions & 0 deletions tests/testthat/test-inline.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
context("Inline")
roc <- rd_roclet()

test_that("Inline comments are supported", {
out <- roc_proc_text(roc, "
#' Description
a <- function(x) {
#' @param x an integer
stopifnot(is.integer(x))
}")[[1]]
expect_equal(get_tag(out, "param")$values, c(x="an integer"))
})

test_that("Inline comments just before the closing brace are allowed", {
out <- roc_proc_text(roc, "
#' Description
a <- function(x) {
#' @param x an integer
stopifnot(is.integer(x))
#' @seealso somewhere
}")[[1]]
expect_equal(get_tag(out, "seealso")$value, "somewhere")
})

test_that("Inline comments do not extend past the closing brace", {
out <- roc_proc_text(roc, "
#' Description
a <- function(x) {
#' @param x an integer
stopifnot(is.integer(x))
}; #' @seealso somewhere")[[1]]
expect_null(get_tag(out, "seealso"))
})