Skip to content

Commit

Permalink
Check compare arguments (#202)
Browse files Browse the repository at this point in the history
Fixes #181
  • Loading branch information
hadley authored Oct 21, 2024
1 parent 9d2fe71 commit e17fa12
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,
S7,
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)
* waldo gains basic support for S7 objects (#200).
* `as_map()` now preserves attributes (#185).
* `compare()` can now distinguish between objects that differ only in the value of their S4 bit (#189).
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_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 e17fa12

Please sign in to comment.