Skip to content

Commit

Permalink
Add selection test and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 24, 2024
1 parent ea256cb commit 5030b41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/topics.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ match_env <- function(topics) {
}
fns$has_lifecycle <- function(x) {
check_string(x)
which(purrr::map_lgl(topics$lifecycle, ~ any(.$name %in% x)))
which(purrr::map_lgl(topics$lifecycle, ~ any(. %in% x)))
}
fns$has_concept <- function(x, internal = FALSE) {
check_string(x)
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-topics.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ test_that("can select by keyword", {
expect_equal(select_topics("has_keyword('c')", topics), integer())
})

test_that("can select by lifecycle", {
topics <- tibble::tribble(
~name, ~alias, ~internal, ~keywords, ~lifecycle,
"b1", "b1", FALSE, "a", list("stable"),
"b2", "b2", FALSE, c("a", "b"), NULL
)
expect_equal(select_topics("has_lifecycle('stable')", topics), 1)
expect_equal(select_topics("has_lifecycle('deprecated')", topics), integer())
})

test_that("can combine positive and negative selections", {
topics <- tibble::tribble(
~name, ~alias, ~internal,
Expand Down

0 comments on commit 5030b41

Please sign in to comment.