From 5030b41b96d7fbc051a2fa4b431aeab50d30dcb3 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 24 May 2024 08:21:31 -0500 Subject: [PATCH] Add selection test and fix bug --- R/topics.R | 2 +- tests/testthat/test-topics.R | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/R/topics.R b/R/topics.R index de61e11cf..b43c75091 100644 --- a/R/topics.R +++ b/R/topics.R @@ -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) diff --git a/tests/testthat/test-topics.R b/tests/testthat/test-topics.R index a4c9c5d5d..ee8be76f6 100644 --- a/tests/testthat/test-topics.R +++ b/tests/testthat/test-topics.R @@ -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,