tests/testthat/test-getNonDefaultArguments.R

test_that("getNonDefaultArguments returns only non-default arguments", {
  testFunction <- function(a = 0, b = 0, ...) {
  }

  expect_length(getNonDefaultArguments(testFunction, args = NULL), 0)
  expect_length(getNonDefaultArguments(testFunction, args = list(a = 0)), 0)
  expect_identical(getNonDefaultArguments(testFunction, args = list(a = 1)), list(a = 1))
  expect_identical(getNonDefaultArguments(testFunction, args = list(a = 0, b = 1, x = 1)), list(b = 1, x = 1))
  expect_identical(getNonDefaultArguments(testFunction, args = list(a = 0, x = 1, b = 1)), list(x = 1, b = 1))
})

test_that("getNonDefaultArguments can handle read + convert with subtype = NULL", {
  readTest <- function(subtype = NULL) {}
  convertTest <- function(x) {}
  globalassign("readTest", "convertTest")

  expect_length(getNonDefaultArguments(c("readTest", "convertTest"),
                                       list(subtype = "a", x = 5)), 2)
})

Try the madrat package in your browser

Any scripts or data that you put into this service are public.

madrat documentation built on July 2, 2026, 9:09 a.m.