tests/testthat/test-fx-fun-ggplot-nomination.R

context("fx-fun-ggplot-nomination")

test_that("Nominations", {
  lay <- ggplot2::geom_point()
  sca <- ggplot2::scale_x_continuous()
  fac <- ggplot2::facet_wrap(ggplot2::vars(x, y))
  coo <- ggplot2::coord_flip()
  oth <- ggplot2::ggproto()
  expect_silent(nom <- nomination(lay, sca, fac, coo, oth))
  expect_equal(nomination(), structure(list(), class = c("nomination", "list")))
  expect_identical(nom_layers(nom), list(lay))
  expect_identical(nom_facets(nom), list(fac))
  expect_identical(nom_scales(nom), list(sca))
  expect_identical(nom_coords(nom), list(coo))
  expect_identical(nom_others(nom), list(oth))
  expect_true(is_nomination(nom))
  expect_identical(unlist(nom), unlist(c(nom, nomination()))[names(nom)])
  lay2 <- ggplot2::geom_line()
  expect_identical(nom_layers(c(nom, nomination(lay2))), list(lay2, lay))
  expect_error(nomination(1))
  expect_error(nom_layers(nom) <- list(LETTERS))
  expect_error(nom_facets(nom) <- list(LETTERS))
  expect_error(nom_scales(nom) <- list(LETTERS))
  expect_error(nom_coords(nom) <- list(LETTERS))
  expect_error(nom_others(nom) <- list(LETTERS))
})

test_that("Lists can be added to a nomination", {
  expect_equal(nomination(list()), nomination())
  p <- ggplot2::geom_point()
  l <- ggplot2::geom_line()
  expect_equal(nomination(list(p, l)), nomination(p, l))
  expect_equal(nomination(p, list(l)), nomination(p, l))
})
sflippl/tectr documentation built on May 6, 2019, 8:51 a.m.