Skip to content

Commit

Permalink
add lookup_remove()
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Nov 10, 2024
1 parent 5439145 commit c5bd721
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/class_lookup.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ lookup_unset <- function(lookup, names) {
}
}

lookup_remove <- function(lookup, names) {
remove(list = names, envir = lookup)
}

lookup_validate <- function(lookup) {
tar_assert_envir(lookup)
}
8 changes: 8 additions & 0 deletions tests/testthat/test-class_lookup.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ tar_test("class lookup", {
expect_silent(lookup_validate(lookup))
})

tar_test("class lookup remove method", {
lookup <- lookup_new()
lookup_set(lookup, names = letters, value = TRUE)
expect_equal(sort(lookup_list(lookup)), sort(letters))
lookup_remove(lookup, letters)
expect_equal(lookup_list(lookup), character(0L))
})

tar_test("class lookup methods on NULL objects", {
expect_false(lookup_exists(NULL, "a"))
expect_true(lookup_missing(NULL, "a"))
Expand Down

0 comments on commit c5bd721

Please sign in to comment.