tests/testthat/test-labs_glue.R

test_that("labs_glue", {
  # cheat about making a ggtibble object
  d_ggtibble <-
    dplyr::tibble(
      A = c("A", "B"),
      B = c("B", "C")
    )
  class(d_ggtibble) <- c("ggtibble", class(d_ggtibble))
  expect_error(
    labs_glue(d_ggtibble),
    regexp = "length(args) > 0 is not TRUE",
    fixed = TRUE
  )
  expect_equal(
    labs_glue(d_ggtibble, y = "A"),
    list(ggplot2::labs(y = "A"))
  )
  expect_equal(
    labs_glue(d_ggtibble, y = "{A}"),
    list(
      ggplot2::labs(y = "A"),
      ggplot2::labs(y = "B")
    )
  )
  expect_equal(
    labs_glue(d_ggtibble, x = NULL, y = "{A}"),
    list(
      ggplot2::labs(x = character(0), y = "A"),
      ggplot2::labs(x = character(0), y = "B")
    )
  )
})

Try the ggtibble package in your browser

Any scripts or data that you put into this service are public.

ggtibble documentation built on June 22, 2024, 10:55 a.m.