Skip to content

Commit f0f4196

Browse files
committed
Dear coveralls, please pass
1 parent 9b4c954 commit f0f4196

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

tests/testthat/test-tex.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
context("underline")
2+
3+
test_that("underline works as expected", {
4+
r <- underline("Hello!")
5+
expect_equal(r, "\\underline{Hello!}")
6+
})
7+
8+
context("applyLatexStyle")
9+
10+
test_that("underline or underline2", {
11+
item <- "Hello!"
12+
item_theme <- list()
13+
item_theme$decoration <- "underline"
14+
r <- applyLatexStyle(item, item_theme)
15+
expect_equal(r, "\\underline{Hello!}")
16+
})
17+
18+
test_that("Warning on hex color", {
19+
item <- "Hello!"
20+
item_theme <- list()
21+
item_theme$font_color <- "#000000"
22+
expect_warning(applyLatexStyle(item, item_theme), "In Latex, colors must be color names not hex codes")
23+
})
24+
25+
test_that("Color application", {
26+
item <- "Hello!"
27+
item_theme <- list()
28+
item_theme$font_color <- "blue"
29+
r <- applyLatexStyle(item, item_theme)
30+
expect_equal(r, "\\color{blue}Hello!")
31+
})
32+
33+
context("validLatexFont")
34+
35+
test_that("Warning on missing font set to helvet", {
36+
expect_warning(validLatexFont("notafont"), "It has been set to")
37+
})

tests/testthat/test-writeCodeBookLatex.R

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,60 @@ with_api_fixture("fixtures-1-2-5", {
2222
expect_true(sum(tex %in% original)/length(tex) > 0.98)
2323

2424
})
25+
26+
test_that("Tex result as expected with features", {
27+
28+
suppressWarnings(
29+
writeCodeBookLatex(
30+
ds,
31+
title = "Hello",
32+
subtitle = "Goodbye",
33+
sample_desc = "US Voting Adults",
34+
logo = "ygblue",
35+
pdf = FALSE)
36+
)
37+
38+
tex <- readLines("Example-dataset.tex")
39+
original <- readRDS("fixtures/writeCodeBookLatexOne.rds")
40+
41+
expect_true(length(tex) == length(original))
42+
expect_true(sum(tex %in% original)/length(tex) > 0.98)
43+
44+
})
45+
46+
test_that("Creates pdf output", {
47+
48+
49+
with_mock(suppressWarnings(
50+
writeCodeBookLatex(
51+
ds,
52+
title = "Hello",
53+
subtitle = "Goodbye",
54+
sample_desc = "US Voting Adults",
55+
logo = "ygblue",
56+
pdf = TRUE)
57+
), "crunchtabs::file.open" = function(x) return(TRUE))
58+
59+
expect_true(file.exists("Example-dataset.pdf"))
60+
expect_true(file.remove("Example-dataset.pdf"))
61+
62+
})
63+
64+
test_that("Tex result set position as expected", {
65+
suppressWarnings(
66+
writeCodeBookLatex(
67+
ds,
68+
title = "Hello",
69+
subtitle = "Goodbye",
70+
sample_desc = "US Voting Adults",
71+
logo = "ygblue",
72+
position = "c",
73+
pdf = FALSE)
74+
)
75+
76+
tex <- readLines("Example-dataset.tex")
77+
expect_true(any(grepl("\\begin{longtable}[c]", tex, fixed = TRUE)))
78+
})
2579
})
2680

2781
with_api_fixture("fixtures-1-2-5", {

0 commit comments

Comments
 (0)