Skip to content

Commit

Permalink
Handle case where param matches more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Apr 28, 2022
1 parent 63a0e4c commit 630ab47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion R/rd-inherit.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ match_param <- function(from, to) {
return(NULL)
}

unique(c(to, to)[match(from, to_std)])
union(
setdiff(to[match(from, to)], NA),
setdiff(to[match(from, flip_dot(to))], NA)
)
}

inherit_dot_params <- function(topic, topics, env) {
Expand Down
23 changes: 22 additions & 1 deletion tests/testthat/test-rd-inherit.R
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ test_that("match_params can ignore . prefix", {
expect_equal(match_param(c(".x", "y"), c(".x", ".y", ".z")), c(".x", ".y"))
expect_equal(match_param(c(".x", "x"), c("x", ".x")), c(".x", "x"))
expect_equal(match_param(c(".x", "x"), "x"), "x")
expect_equal(match_param("x", c(".x", "x")), c("x", ".x"))
})

test_that("multiple @inheritParam tags gathers all params", {
Expand All @@ -299,7 +300,6 @@ test_that("multiple @inheritParam tags gathers all params", {
#' @param x X
a <- function(x) {}
#' B
#'
#' @param y Y
Expand Down Expand Up @@ -354,6 +354,27 @@ test_that("@inheritParam preserves mixed names", {
expect_equal(out$get_value("param"), c(".x,x" = "X"))
})

test_that("can inherit from same arg twice", {
out <- roc_proc_text(rd_roclet(), "
#' A.
#'
#' @param x X
a <- function(x) {}
#' B
#'
#' @inheritParams a
b <- function(x) {}
#' C
#'
#' @inheritParams a
#' @rdname b
c <- function(.x) {}
")[[2]]
expect_equal(out$get_value("param"), c("x,.x" = "X"))
})

test_that("@inheritParams can inherit from inherited params", {
out <- roc_proc_text(rd_roclet(), "
#' C
Expand Down

0 comments on commit 630ab47

Please sign in to comment.