Skip to content

Commit

Permalink
better names in coverage report
Browse files Browse the repository at this point in the history
Give the `cov$functions` columns more informative names, for interactive development. E.g.:

> cov$functions
 [1] "Range@properties$length$getter"
 [2] "Range@properties$length$setter"
 [3] "Range@properties$length$setter"
 [4] "Range@constructor"
 [5] "Range@validator"
 [6] "Range@validator"
 [7] "Range@validator"
 [8] "Range@validator"
 [9] "Range@validator"
[10] "Range@validator"
[11] "method(inside, TestS7::Range)"
  • Loading branch information
t-kalinowski committed Nov 8, 2024
1 parent 59b1f7e commit 580544d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions R/S7.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ traverse_S7_generic <- function(x) {
# Recurse for nested environments
get_replacements(target_value)
} else {
name <- as.character(attr(target_value, "name", TRUE) %||% name)
list(replacement(name, env, target_value))
}
})
Expand All @@ -28,20 +29,24 @@ traverse_S7_generic <- function(x) {
}

traverse_S7_class <- function(x) {
class_name <- S7::prop(x, "name")
prop_fun_replacements <-
lapply(S7::prop(x, "properties"), function(p) {
lapply(c("getter", "setter", "validator"), function(prop_fun) {
if (!is.null(p[[prop_fun]])) {
replacement(prop_fun, env = p, target_value = p[[prop_fun]])
replacement(
sprintf("%s@properties$%s$%s", class_name, p$name, prop_fun),
env = p,
target_value = p[[prop_fun]])
}
})
})
prop_fun_replacements <- unlist(prop_fun_replacements, FALSE, FALSE)

c(
list(
replacement("constructor", env = x, target_value = S7::prop(x, "constructor")),
replacement("validator" , env = x, target_value = S7::prop(x, "validator"))
replacement(paste0(class_name, "@constructor"), env = x, target_value = S7::prop(x, "constructor")),
replacement(paste0(class_name, "@validator") , env = x, target_value = S7::prop(x, "validator"))
),
prop_fun_replacements
)
Expand Down

0 comments on commit 580544d

Please sign in to comment.