Will Beasley | 883d0e0 | 2017-07-22 02:15:15 -0500 | [diff] [blame] | 1 | library(testthat) |
| 2 | library(knitr) |
| 3 | |
| 4 | dt <- mtcars[1:5, 1:8] |
| 5 | |
| 6 | |
| 7 | # ---- styling ----------------------------------------------------------------- |
| 8 | testthat::context("styling") |
| 9 | |
| 10 | test_that("dry_run", { |
| 11 | observed <- dt[1:3] %>% |
| 12 | kable(format = "latex", booktabs = T, caption = "xxx") %>% |
| 13 | kable_styling(latex_options = c("striped", "hold_position"), font_size = 6, position = "float_left") |
| 14 | # dput(observed) |
| 15 | |
Hao Zhu | eba4198 | 2017-08-03 10:25:38 -0400 | [diff] [blame^] | 16 | expected <- |
| 17 | structure( |
| 18 | "\\rowcolors{2}{gray!6}{white}\n\\begin{wraptable}{l}{6.6cm}\n\n\\caption{\\label{tab:}xxx}\n\\centering\n\\fontsize{6}{8}\\selectfont\n\\begin{tabular}[t]{lrrr}\n\\hiderowcolors\n\\toprule\n & mpg & cyl & disp\\\\\n\\midrule\n\\showrowcolors\nMazda RX4 & 21.0 & 6 & 160\\\\\nMazda RX4 Wag & 21.0 & 6 & 160\\\\\nDatsun 710 & 22.8 & 4 & 108\\\\\nHornet 4 Drive & 21.4 & 6 & 258\\\\\nHornet Sportabout & 18.7 & 8 & 360\\\\\n\\bottomrule\n\\end{tabular}\n\\end{wraptable}\n\\rowcolors{2}{white}{white}", |
| 19 | format = "latex", |
| 20 | class = "knitr_kable", |
| 21 | kable_meta = structure( |
| 22 | list( |
| 23 | tabular = "tabular", |
| 24 | booktabs = TRUE, |
| 25 | align = "lrrr", |
| 26 | valign = "[t]", |
| 27 | ncol = 4L, |
| 28 | nrow = 6, |
| 29 | colnames = c(" ", "mpg", "cyl", "disp"), |
| 30 | rownames = c("", "Mazda", "Mazda", "Datsun", "Hornet", |
| 31 | "Hornet"), |
| 32 | caption = "\\label{tab:}x", |
| 33 | contents = c( |
| 34 | " & mpg & cyl & disp", |
| 35 | "Mazda RX4 & 21.0 & 6 & 160", |
| 36 | "Mazda RX4 Wag & 21.0 & 6 & 160", |
| 37 | "Datsun 710 & 22.8 & 4 & 108", |
| 38 | "Hornet 4 Drive & 21.4 & 6 & 258", |
| 39 | "Hornet Sportabout & 18.7 & 8 & 360" |
| 40 | ), |
| 41 | centering = TRUE, |
| 42 | table_env = TRUE, |
| 43 | align_vector = c("l", "r", "r", "r"), |
| 44 | align_vector_origin = c("l", |
| 45 | "r", "r", "r"), |
| 46 | valign2 = "\\[t\\]", |
| 47 | valign3 = "t", |
| 48 | begin_tabular = "\\\\begin\\{tabular\\}\\[t\\]", |
| 49 | end_tabular = "\\\\end\\{tabular\\}" |
| 50 | ), |
| 51 | .Names = c( |
| 52 | "tabular", |
| 53 | "booktabs", |
| 54 | "align", |
| 55 | "valign", |
| 56 | "ncol", |
| 57 | "nrow", |
| 58 | "colnames", |
| 59 | "rownames", |
| 60 | "caption", |
| 61 | "contents", |
| 62 | "centering", |
| 63 | "table_env", |
| 64 | "align_vector", |
| 65 | "align_vector_origin", |
| 66 | "valign2", |
| 67 | "valign3", |
| 68 | "begin_tabular", |
| 69 | "end_tabular" |
| 70 | ) |
| 71 | ) |
| 72 | ) |
Will Beasley | 883d0e0 | 2017-07-22 02:15:15 -0500 | [diff] [blame] | 73 | |
| 74 | expect_equal(observed, expected) |
| 75 | }) |