Hao Zhu | 3f65f18 | 2019-01-22 02:55:46 -0500 | [diff] [blame] | 1 | context("add_indent") |
| 2 | |
| 3 | test_that("add_indent can add to 1 row", { |
| 4 | observed <- kable(mtcars[1:4, 1:3], "latex") %>% |
| 5 | add_indent(1) %>% |
| 6 | as.character() |
| 7 | expected <- "\n\\begin{tabular}{l|r|r|r}\n\\hline\n & mpg & cyl & disp\\\\\n\\hline\n\\hspace{1em}Mazda RX4 & 21.0 & 6 & 160\\\\\n\\hline\nMazda RX4 Wag & 21.0 & 6 & 160\\\\\n\\hline\nDatsun 710 & 22.8 & 4 & 108\\\\\n\\hline\nHornet 4 Drive & 21.4 & 6 & 258\\\\\n\\hline\n\\end{tabular}" |
| 8 | expect_equal(observed, expected) |
| 9 | }) |
| 10 | |
| 11 | test_that("add_indent can be added multiple times.", { |
| 12 | observed <- kable(mtcars[1:4, 1:3], "latex") %>% |
| 13 | add_indent(1:3) %>% |
| 14 | add_indent(1) %>% |
| 15 | as.character() |
| 16 | expected <- "\n\\begin{tabular}{l|r|r|r}\n\\hline\n & mpg & cyl & disp\\\\\n\\hline\n\\hspace{1em}\\hspace{1em}Mazda RX4 & 21.0 & 6 & 160\\\\\n\\hline\n\\hspace{1em}Mazda RX4 Wag & 21.0 & 6 & 160\\\\\n\\hline\n\\hspace{1em}Datsun 710 & 22.8 & 4 & 108\\\\\n\\hline\nHornet 4 Drive & 21.4 & 6 & 258\\\\\n\\hline\n\\end{tabular}" |
| 17 | expect_equal(observed, expected) |
| 18 | }) |
| 19 | |
Damian Thomas | f36f960 | 2021-04-28 09:59:51 -0400 | [diff] [blame] | 20 | test_that("add_indent can add to an interior column.", { |
| 21 | observed <- kable(mtcars[1:4, 1:3], "latex") %>% |
| 22 | add_indent(1:3, target_cols = 2) %>% |
| 23 | as.character() |
| 24 | expected <- "\n\\begin{tabular}{l|r|r|r}\n\\hline\n & mpg & cyl & disp\\\\\n\\hline\nMazda RX4 & \\hspace{1em}21.0 & 6 & 160\\\\\n\\hline\nMazda RX4 Wag & \\hspace{1em}21.0 & 6 & 160\\\\\n\\hline\nDatsun 710 & \\hspace{1em}22.8 & 4 & 108\\\\\n\\hline\nHornet 4 Drive & 21.4 & 6 & 258\\\\\n\\hline\n\\end{tabular}" |
| 25 | expect_equal(observed, expected) |
| 26 | }) |
Hao Zhu | 3f65f18 | 2019-01-22 02:55:46 -0500 | [diff] [blame] | 27 | |
Damian Thomas | f36f960 | 2021-04-28 09:59:51 -0400 | [diff] [blame] | 28 | test_that("add_indent can add to an interior column multiple times.", { |
| 29 | observed <- kable(mtcars[1:4, 1:3], "latex") %>% |
| 30 | add_indent(1:3, target_cols = 2) %>% |
| 31 | add_indent(1, target_cols = 2) %>% |
| 32 | as.character() |
| 33 | expected <- "\n\\begin{tabular}{l|r|r|r}\n\\hline\n & mpg & cyl & disp\\\\\n\\hline\nMazda RX4 & \\hspace{1em}\\hspace{1em}21.0 & 6 & 160\\\\\n\\hline\nMazda RX4 Wag & \\hspace{1em}21.0 & 6 & 160\\\\\n\\hline\nDatsun 710 & \\hspace{1em}22.8 & 4 & 108\\\\\n\\hline\nHornet 4 Drive & 21.4 & 6 & 258\\\\\n\\hline\n\\end{tabular}" |
| 34 | expect_equal(observed, expected) |
| 35 | }) |