library(testthat)
context("htmlTable - dimnames")
test_that("First dimname should be converted to rgroup, tspanner or rowlabel", {
var1 <- LETTERS[1:3]
var2 <- LETTERS[c(4:5, 5)]
basic_label <-
table(var1, var2) %>%
htmlTable(css.rgroup = "background: blue")
expect_match(basic_label, "
]+background: blue[^>]+>var1 |
",
info = "Expect the variable name to appear as an rgroup")
expect_match(basic_label, "]+> A | ",
info = "Expect the variable name to appear as an rgroup")
expect_match(basic_label, "]+> B | ",
info = "Expect the variable name to appear as an rgroup")
expect_match(basic_label, "]+> C | ",
info = "Expect the variable name to appear as an rgroup")
tspanner_label <-
table(var1, var2) %>%
htmlTable(rgroup=c("alt"),
n.rgroup=c(3),
css.tspanner = "background: red",
css.rgroup = "background: blue")
expect_match(tspanner_label, "]+background: red[^>]+>var1 |
",
info = "Expect the variable name to appear as an tspanner")
expect_match(tspanner_label, "]+background: blue[^>]+>alt |
",
info = "Expect the rgroup name to appear as usual")
expect_match(tspanner_label, "]+> A | ")
expect_match(tspanner_label, "]+> B | ")
expect_match(tspanner_label, "]+> C | ")
rowlabel_label <-
table(var1, var2) %>%
htmlTable(rgroup=c("alt"),
n.rgroup=c(3),
tspanner=c("alt2"),
n.tspanner = c(3),
css.tspanner = "background: red",
css.rgroup = "background: blue")
expect_match(rowlabel_label, "]+background: red[^>]+>alt2 |
",
info = "Expect the variable name to appear as an tspanner")
expect_match(rowlabel_label, "]+background: blue[^>]+>alt |
",
info = "Expect the rgroup name to appear as usual")
expect_match(rowlabel_label, "]+> A | ")
expect_match(rowlabel_label, "]+> B | ")
expect_match(rowlabel_label, "]+> C | ")
})
test_that("Second dimname should be converted to cgroup", {
var1 <- LETTERS[1:3]
var2 <- LETTERS[c(4:5, 5)]
basic_label <-
table(var1, var2) %>%
htmlTable
expect_match(basic_label, "]+>var2 | ",
info = "Expect the variable name to appear as a cgroup")
})