Просмотр исходного кода

Check that hex colors only have hex characters

tags/v0.3.0
Garrick Aden-Buie 6 лет назад
Родитель
Сommit
021053a0ee
2 измененных файлов: 4 добавлений и 2 удалений
  1. +1
    -1
      R/color.R
  2. +3
    -1
      tests/testthat/test-color.R

+ 1
- 1
R/color.R Просмотреть файл

} }


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 Просмотреть файл



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"))
}) })
}) })

Загрузка…
Отмена
Сохранить