Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort names of R6 objects correctly #85

Merged
merged 3 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions R/compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,13 @@ compare_structure <- function(x, y, paths = c("x", "y"), opts = compare_opts())
if (env_has(x, ".__enclos_env__")) {
# enclosing env of methods is object env
opts$ignore_function_env <- TRUE
x_fields <- as.list(x, sorted = TRUE)
y_fields <- as.list(y, sorted = TRUE)
x_fields <- as.list(x)
y_fields <- as.list(y)
x_fields$.__enclos_env__ <- NULL
y_fields$.__enclos_env__ <- NULL
# Can't use as.list(sorted = TRUE), https://github.com/r-lib/waldo/issues/84
x_fields <- x_fields[order(names(x_fields))]
y_fields <- y_fields[order(names(y_fields))]

out <- c(out, compare_structure(x_fields, y_fields, paths, opts = opts))
} else {
Expand Down
7 changes: 5 additions & 2 deletions tests/testthat/test-compare-r6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ v No differences
`old` is length 3
`new` is length 4

`names(old)`: "x" "clone" "initialize"
`names(new)`: "y" "x" "clone" "initialize"
`names(old)`: "clone" "initialize" "x"
`names(new)`: "clone" "initialize" "x" "y"

`old$y` is absent
`new$y` is a double vector (10)

> compare(froofy$new(1), froofy$new(1)$clone())
v No differences

2 changes: 2 additions & 0 deletions tests/testthat/test-compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ test_that("can compare R6 objects", {
compare(goofy$new(1), goofy$new(1))
compare(goofy$new(1), goofy$new("a"))
compare(goofy$new(1), froofy$new(1))
# https://github.com/r-lib/waldo/issues/84
compare(froofy$new(1), froofy$new(1)$clone())
})
})

Expand Down