Skip to content

Commit

Permalink
add tests for internal variables i/layers
Browse files Browse the repository at this point in the history
  • Loading branch information
yjunechoe committed Oct 13, 2024
1 parent 2c96752 commit b62f4bd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/testthat/test-sublayer-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,34 @@ test_that("checks throwing errors", {
})

})

test_that("`layer_is()` targets layers with `i` and `layers`", {

p <- ggplot(diamonds) +
stat_count(geom = "label", aes(cut, label = after_stat(count))) +
stat_count(geom = "label", aes(cut, label = after_stat(count)), color = "red") +
stat_count(geom = "label", aes(cut, label = after_stat(count)))

expect_identical(
inspect_which(p, StatCount$compute_group, cond = TRUE),
c(
inspect_which(p, StatCount$compute_group, cond = layer_is(1)),
inspect_which(p, StatCount$compute_group, cond = layer_is(2)),
inspect_which(p, StatCount$compute_group, cond = layer_is(3))
)
)

expect_identical(
c(
inspect_which(p, StatCount$compute_group, cond = layer_is(1)),
inspect_which(p, StatCount$compute_group, cond = layer_is(3))
),
inspect_which(p, StatCount$compute_group, cond = layer_is(i %in% c(1, 3)))
)

expect_identical(
inspect_which(p, StatCount$compute_group, cond = layer_is(2)),
inspect_which(p, StatCount$compute_group, cond = layer_is(!is.null(layers[[i]]$aes_params$colour)))
)

})

0 comments on commit b62f4bd

Please sign in to comment.