Sfoglia il codice sorgente

bulma_column_narrow() accepts TRUE/FALSE

master
Garrick Aden-Buie 7 anni fa
parent
commit
7b1b0a9545
5 ha cambiato i file con 36 aggiunte e 7 eliminazioni
  1. +2
    -0
      DESCRIPTION
  2. +2
    -0
      R/columns.R
  3. +12
    -7
      R/utils.R
  4. +4
    -0
      tests/testthat.R
  5. +16
    -0
      tests/testthat/test-columns.R

+ 2
- 0
DESCRIPTION Vedi File

LazyData: true LazyData: true
RoxygenNote: 6.1.1 RoxygenNote: 6.1.1
Roxygen: list(markdown = TRUE) Roxygen: list(markdown = TRUE)
Suggests:
testthat

+ 2
- 0
R/columns.R Vedi File

bulma_column_narrow <- function(viewport = NULL) { bulma_column_narrow <- function(viewport = NULL) {
ret <- if (is.null(viewport)) { ret <- if (is.null(viewport)) {
"is-narrow" "is-narrow"
} else if (is.logical(viewport)) {
if (isTRUE(viewport)) "is-narrow" else return(NULL)
} else { } else {
viewport <- validate_viewport(viewport) viewport <- validate_viewport(viewport)
c_is(c_prefix(viewport, "narrow-")) c_is(c_prefix(viewport, "narrow-"))

+ 12
- 7
R/utils.R Vedi File

validate_value <- function(value = NULL, choices, several.ok = TRUE, value_name = "") { validate_value <- function(value = NULL, choices, several.ok = TRUE, value_name = "") {
if (!is.null(value) && length(value)) { if (!is.null(value) && length(value)) {
value_name <- if (nchar(value_name) > 0) glue("`{value_name}` - ") else "" value_name <- if (nchar(value_name) > 0) glue("`{value_name}` - ") else ""
if (!several.ok && length(value) > 1) {
msg <- glue("{value_name}Using the first of {length(value)} values: {value[1]}")
rlang::warn(msg)
value <- value[1]
}
warnings <- c()
not_in_choices <- setdiff(value, choices) not_in_choices <- setdiff(value, choices)
if (length(not_in_choices)) { if (length(not_in_choices)) {
msg <- glue("{value_name}Ignoring invalid choices: ",
warnings <- glue("{value_name}Ignoring invalid choices: ",
"\"{paste(not_in_choices, collapse = '\", \"')}\"") "\"{paste(not_in_choices, collapse = '\", \"')}\"")
rlang::warn(msg)
value <- intersect(value, choices) value <- intersect(value, choices)
} }
if (!several.ok && length(value) > 1) {
warnings <- c(
warnings,
glue("{value_name}Using the first of {length(value)} values: {value[1]}")
)
value <- value[1]
}
if (length(value)) { if (length(value)) {
if (length(warnings)) {
rlang::warn(paste(warnings, collapse = "\n"))
}
value value
} else { } else {
rlang::abort(glue("{value_name}Must be one of the following valid choices: ", rlang::abort(glue("{value_name}Must be one of the following valid choices: ",

+ 4
- 0
tests/testthat.R Vedi File

library(testthat)
library(bulma)

test_check("bulma")

+ 16
- 0
tests/testthat/test-columns.R Vedi File

context("test-columns")

test_that("bulma_column_narrow() handles viewport and logical", {
expect_equal_unclass <- function(x, y) {
expect_equal(unclass(x), y)
}
expect_equal_unclass(bulma_column_narrow("touch"), "is-narrow-touch")
expect_equal_unclass(bulma_column_narrow("desktop"), "is-narrow-desktop")
expect_s3_class(bulma_column_narrow("desktop"), "bulma_column_narrow")
expect_equal_unclass(bulma_column_narrow(TRUE), "is-narrow")
expect_equal_unclass(bulma_column_narrow(), "is-narrow")
expect_null(bulma_column_narrow(FALSE))
expect_error(bulma_column_narrow("touchscreen"))
expect_warning(bulma_column_narrow(c("touch", "desktop")))
expect_warning(bulma_column_narrow(c("touchscreen", "touch")))
})

Loading…
Annulla
Salva