Skip to content

Commit

Permalink
Check compare arguments
Browse files Browse the repository at this point in the history
Fixes #181
  • Loading branch information
hadley committed Oct 21, 2024
1 parent 7d818b9 commit 4229465
Show file tree
Hide file tree
Showing 5 changed files with 935 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Imports:
diffobj (>= 0.3.4),
glue,
methods,
rlang (>= 1.0.0)
rlang (>= 1.1.0)
Suggests:
R6,
testthat (>= 3.0.0),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# waldo (development version)

* `compare()` now gives informative errors if you misspecify the argument types (#181)
* Double comparisons now always display one more digit than the absolute minimum necessary (#141).
* waldo no longer imports tibble and rematch2 (@olivroy, #196).
* waldo now requires R 4.0.0.
Expand Down
16 changes: 15 additions & 1 deletion R/compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
#' this is R's default behaviour. Use `FALSE` when specifically concerned
#' with the encoding, not just the value of the string.
#' @param list_as_map Compare lists as if they are mappings between names and
#' values. Concretely, this drops `NULLs` in both objects and sorts named
#' values. Concretely, this drops `NULL`s in both objects and sorts named
#' components.
#' @param quote_strings Should strings be surrounded by quotes? If `FALSE`,
#' only side-by-side and line-by-line comparisons will be used, and there's
Expand Down Expand Up @@ -137,6 +137,20 @@ compare <- function(x, y, ...,
quote_strings = TRUE
) {

check_string(x_arg)
check_string(y_arg)
check_number_decimal(tolerance, allow_null = TRUE, min = 0)
check_number_whole(max_diffs, min = 1, allow_infinite = TRUE)
check_bool(ignore_srcref)
if (!isTRUE(ignore_attr) && !is.character(ignore_attr)) {
stop_input_type(ignore_attr, "a TRUE or a character vector")

Check warning on line 146 in R/compare.R

View check run for this annotation

Codecov / codecov/patch

R/compare.R#L146

Added line #L146 was not covered by tests
}
check_bool(ignore_encoding)
check_bool(ignore_function_env)
check_bool(ignore_formula_env)
check_bool(list_as_map)
check_bool(quote_strings)

opts <- compare_opts(
...,
tolerance = tolerance,
Expand Down
Loading

0 comments on commit 4229465

Please sign in to comment.