Skip to content

Commit

Permalink
Allow trailing comma in box::use()
Browse files Browse the repository at this point in the history
This commit allows empty expressions to be passed to `box::use()`, which
causes a trailing comma to be legal.

Resolves #172.
  • Loading branch information
klmr committed Mar 20, 2021
1 parent 6da6f10 commit 0def6af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/use.r
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ use = function (...) {
#' @keywords internal
#' @name importing
use_one = function (declaration, alias, caller) {
# Permit empty expression resulting from trailing comma.
if (identical(declaration, quote(expr =)) && identical(alias, '')) return()
spec = parse_spec(declaration, alias)
info = rethrow_on_error(find_mod(spec, caller), sys.call(-1L))
load_and_register(spec, info, caller)
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-basic.r
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ test_that('partial name causes error', {
expect_s3_class(error, 'simpleError')
expect_identical(error$call, quote(a$doubl))
})

test_that('trailing comma is accepted', {
expect_error(box::use(mod/a, ), NA)
expect_error(box::use(mod/a, mod/b, ), NA)
})

0 comments on commit 0def6af

Please sign in to comment.