Przeglądaj źródła

Check that hex colors only have hex characters

tags/v0.3.0
Garrick Aden-Buie 6 lat temu
rodzic
commit
021053a0ee
2 zmienionych plików z 4 dodań i 2 usunięć
  1. +1
    -1
      R/color.R
  2. +3
    -1
      tests/testthat/test-color.R

+ 1
- 1
R/color.R Wyświetl plik

} }


full_length_hex <- function(x) { 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')) stop(paste0('"', x, '" is not a hexadecimal color'))
} }
x <- sub("^#", "", x) x <- sub("^#", "", x)

+ 3
- 1
tests/testthat/test-color.R Wyświetl plik



it("requires valid CSS names", { it("requires valid CSS names", {
expect_error(prepare_colors(c("light blue" = "#88f"))) 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", { it("returns list with color_name and value for each color", {


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

Ładowanie…
Anuluj
Zapisz