File: htmlTable_addHtmlTableStyle.R

package info (click to toggle)
r-cran-htmltable 2.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,600 kB
  • sloc: javascript: 6,797; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,150 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
library(testthat)
library(XML)

test_that("Standard addHtmlTableStyle",{
  mx <- matrix(1:6, ncol = 3)
  colnames(mx) <- sprintf("Col %s", LETTERS[1:NCOL(mx)])


  expect_true(mx %>%
                addHtmlTableStyle(align = "r|r") %>%
                hasHtmlTableStyle("align"))

  style <- mx %>%
    addHtmlTableStyle(align = "r|r",
                      # Check partial match.arg for "bottom"
                      pos.caption = "bot") %>%
    getHtmlTableStyle()
  expect_list(style)


  expect_equal(style$align, "r|r")
  expect_equal(style$pos.caption, "bottom")

  expect_error(mx %>% addHtmlTableStyle(pos.caption = "invalid option"), regexp = "pos.caption")
})

test_that("Wrap addHtmlTable should work", {
  firstWrapper <- function(x, css = c("large", "small")) {
    css.table <- match.arg(css)

    addHtmlTableStyle(x, css.table = css.table)
  }

  v <- firstWrapper(x = mtcars, css = "large")
  expect_equal(getHtmlTableStyle(v)$css.table, "large")

  secondWrapper <- function(x) {
    value <- "small"
    firstWrapper(x, css = value)
  }
  v <- secondWrapper(x = mtcars)
  expect_equal(getHtmlTableStyle(v)$css.table, "small")
})