Explorar el Código

Check that hex colors only have hex characters

tags/v0.3.0
Garrick Aden-Buie hace 6 años
padre
commit
021053a0ee
Se han modificado 2 ficheros con 4 adiciones y 2 borrados
  1. +1
    -1
      R/color.R
  2. +3
    -1
      tests/testthat/test-color.R

+ 1
- 1
R/color.R Ver fichero

@@ -23,7 +23,7 @@ prepare_colors <- function(colors = NULL) {
}

full_length_hex <- function(x) {
if (!grepl("^#", x)) {
if (!grepl("^#", x) || grepl("[^#0-9a-fA-F]", x)) {
stop(paste0('"', x, '" is not a hexadecimal color'))
}
x <- sub("^#", "", x)

+ 3
- 1
tests/testthat/test-color.R Ver fichero

@@ -13,7 +13,7 @@ describe("prepare_colors()", {

it("requires valid CSS names", {
expect_error(prepare_colors(c("light blue" = "#88f")))
expect_error(preapre_colors(c("light/blue" = "#88f")))
expect_error(prepare_colors(c("light/blue" = "#88f")))
})

it("returns list with color_name and value for each color", {
@@ -37,5 +37,7 @@ describe("full_length_hex()", {

it("errors if not a hex color", {
expect_error(full_length_hex("123abc"))
expect_error(full_length_hex("#1234567"))
expect_error(full_length_hex("#00000Z"))
})
})

Cargando…
Cancelar
Guardar