Skip to content

Commit 725ed5f

Browse files
committed
improve coverage
1 parent 03d3092 commit 725ed5f

8 files changed

+40
-22
lines changed

DESCRIPTION

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Suggests:
3232
vdiffr,
3333
viridisLite
3434
Copyright: See LICENSE.note file.
35+
Config/testthat/edition: 3
3536
Encoding: UTF-8
3637
LazyData: true
3738
Roxygen: list(markdown = TRUE)

R/completeme.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# borrowed main bits from https://github.com/jimhester/completeme (when it is put on CRAN will import directly from it)
2-
2+
# nocov start
33
the <- new.env(parent = emptyenv())
44
the$completions <- list()
55
complete_token <- get(".completeToken", asNamespace("utils"))
@@ -137,3 +137,4 @@ paletteer_d_completer <- function(env) {
137137
rc.options(custom.completer = completeme)
138138
register_completion(paletteer = paletteer_d_completer)
139139
}
140+
# nocov end

R/paletteer_c_wrappers.R

-13
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,6 @@ paletteer_c_ggthemes <- function(name, n) {
3737

3838
name <- try(match.arg(name, c(ggthemes_c_seq_names, ggthemes_c_div_names)), silent = T)
3939

40-
if (inherits(name, "try-error")) {
41-
ggthemes_list <- paste(c(
42-
ggthemes_c_seq_names,
43-
ggthemes_c_div_names
44-
),
45-
collapse = "\n"
46-
)
47-
stop(sprintf(
48-
'Error in match.arg, "arg" should be one of: \n%s',
49-
ggthemes_list
50-
))
51-
}
52-
5340
if (name %in% ggthemes_c_seq_names) {
5441
pal_gen <- ggthemes::tableau_seq_gradient_pal(palette = name)
5542
} else {

tests/testthat/_snaps/paletteer_d.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# paletteer_d errors with wrong names
2+
3+
Code
4+
paletteer_d("paletteer::notreal")
5+
Condition
6+
Error in `check_palette()`:
7+
! Palette not found. Make sure both package and palette name are spelled correct in the format "package::palette"
8+

tests/testthat/test-paletteer_c.R

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test-paletteer_c")
2-
31
test_that("paletteer_c return correct number of colors", {
42
expect_length(paletteer_c("grDevices::rainbow", 3), 3)
53
expect_length(paletteer_c("grDevices::rainbow", 9), 9)
@@ -42,3 +40,24 @@ test_that("paletteer_c works when called from another function", {
4240
paletteer_c("grDevices::rainbow", 4)
4341
)
4442
})
43+
44+
test_that("paletteer_c works with ggthemes", {
45+
expect_identical(
46+
length(paletteer_c("ggthemes::Blue", n = 4)),
47+
4L
48+
)
49+
50+
expect_identical(
51+
length(paletteer_c("ggthemes::Orange-Blue Diverging", n = 5)),
52+
5L
53+
)
54+
})
55+
56+
test_that("paletteer_c works with harrypotter", {
57+
expect_identical(
58+
length(paletteer_c("harrypotter::always", n = 4)),
59+
4L
60+
)
61+
})
62+
63+

tests/testthat/test-paletteer_c_wrappers.R

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test-paletteer_c-wrappers")
2-
31
test_that("paletteer_c_ggthemes return correct number of colors", {
42
testthat::skip_if_not_installed("ggthemes")
53
expect_length(paletteer_c_ggthemes("Blue", 10), 10)

tests/testthat/test-paletteer_d.R

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test-paletteer_d")
2-
31
test_that("paletteer_d return correct number of colors", {
42
expect_length(paletteer_d("wesanderson::Royal1", 3), 3)
53
expect_length(paletteer_d("grDevices::blues9", 9), 9)
@@ -66,3 +64,11 @@ test_that("palettes_d_names has the right number of rows", {
6664
nrow(palettes_d_names)
6765
)
6866
})
67+
68+
test_that("paletteer_d errors with wrong names", {
69+
expect_snapshot(
70+
error = TRUE,
71+
paletteer_d("paletteer::notreal")
72+
)
73+
})
74+

tests/testthat/test-paletteer_dynamic.R

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test-paletteer_dynamic")
2-
31
test_that("paletteer_dynamic return correct number of colors", {
42
expect_length(paletteer_dynamic("ggthemes_solarized::green", 1), 1)
53
expect_length(paletteer_dynamic("ggthemes_solarized::green", 3), 3)

0 commit comments

Comments
 (0)