|
| 1 | +capture_print <- function(x){ |
| 2 | + capture.output(print(x,console_width = 80, method = "docx")) |
| 3 | +} |
| 4 | + |
| 5 | +test_that("vector printing to console - numeric", { |
| 6 | + styled_vect <- |
| 7 | + color_vctr(c(1, 2, 0.05, 20), |
| 8 | + text_color = c("red", "blue", "green", NA), |
| 9 | + style = c("bold","italic","strikethrough",NA), |
| 10 | + background = c("teal",NA,"yellow",NA)) |
| 11 | + |
| 12 | + expect_equal( |
| 13 | + capture_print(styled_vect), |
| 14 | + c("`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"darkCyan\"/><w:b/><w:color w:val=\"#FF0000\"/></w:rPr><w:t xml:space=\"preserve\"> 1.00</w:t></w:r>`{=openxml}", |
| 15 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:i/><w:color w:val=\"#0000FF\"/></w:rPr><w:t xml:space=\"preserve\"> 2.00</w:t></w:r>`{=openxml}", |
| 16 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"yellow\"/><w:strike/><w:color w:val=\"#00FF00\"/></w:rPr><w:t xml:space=\"preserve\"> 0.05</w:t></w:r>`{=openxml}", |
| 17 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"></w:rPr><w:t xml:space=\"preserve\">20.00</w:t></w:r>`{=openxml}" ) |
| 18 | + ) |
| 19 | + |
| 20 | +}) |
| 21 | + |
| 22 | +test_that("vector printing to console - integer", { |
| 23 | + styled_vect <- |
| 24 | + color_vctr(as.integer(c(1, 2, 3, 20)), |
| 25 | + text_color = c("red", "blue", "green", NA), |
| 26 | + style = c("bold","italic","strikethrough",NA), |
| 27 | + background = c("teal",NA,"yellow",NA)) |
| 28 | + |
| 29 | + expect_equal( |
| 30 | + capture_print(styled_vect), |
| 31 | + c("`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"darkCyan\"/><w:b/><w:color w:val=\"#FF0000\"/></w:rPr><w:t xml:space=\"preserve\"> 1</w:t></w:r>`{=openxml}", |
| 32 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:i/><w:color w:val=\"#0000FF\"/></w:rPr><w:t xml:space=\"preserve\"> 2</w:t></w:r>`{=openxml}", |
| 33 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"yellow\"/><w:strike/><w:color w:val=\"#00FF00\"/></w:rPr><w:t xml:space=\"preserve\"> 3</w:t></w:r>`{=openxml}", |
| 34 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"></w:rPr><w:t xml:space=\"preserve\">20</w:t></w:r>`{=openxml}") |
| 35 | + ) |
| 36 | +}) |
| 37 | + |
| 38 | +test_that("vector printing to console - character", { |
| 39 | + styled_vect <- |
| 40 | + color_vctr(c("A", "B", "C", "Long Character"), |
| 41 | + text_color = c("red", "blue", "green", NA), |
| 42 | + style = c("bold","italic","strikethrough",NA), |
| 43 | + background = c("teal",NA,"yellow",NA)) |
| 44 | + |
| 45 | + |
| 46 | + expect_equal( |
| 47 | + capture_print(styled_vect), |
| 48 | + c("`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"darkCyan\"/><w:b/><w:color w:val=\"#FF0000\"/></w:rPr><w:t xml:space=\"preserve\">A </w:t></w:r>`{=openxml}", |
| 49 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:i/><w:color w:val=\"#0000FF\"/></w:rPr><w:t xml:space=\"preserve\">B </w:t></w:r>`{=openxml}", |
| 50 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"yellow\"/><w:strike/><w:color w:val=\"#00FF00\"/></w:rPr><w:t xml:space=\"preserve\">C </w:t></w:r>`{=openxml}", |
| 51 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"></w:rPr><w:t xml:space=\"preserve\">Long Character</w:t></w:r>`{=openxml}") |
| 52 | + ) |
| 53 | + |
| 54 | +}) |
| 55 | + |
| 56 | +test_that("vector printing to console - factor", { |
| 57 | + styled_vect <- |
| 58 | + color_vctr(factor(c("A", "B", "C", "Long Character")), |
| 59 | + text_color = c("red", "blue", "green", NA), |
| 60 | + style = c("bold","italic","strikethrough",NA), |
| 61 | + background = c("teal",NA,"yellow",NA)) |
| 62 | + |
| 63 | + expect_equal( |
| 64 | + capture_print(styled_vect), |
| 65 | + c("`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"darkCyan\"/><w:b/><w:color w:val=\"#FF0000\"/></w:rPr><w:t xml:space=\"preserve\">A </w:t></w:r>`{=openxml}", |
| 66 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:i/><w:color w:val=\"#0000FF\"/></w:rPr><w:t xml:space=\"preserve\">B </w:t></w:r>`{=openxml}", |
| 67 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"yellow\"/><w:strike/><w:color w:val=\"#00FF00\"/></w:rPr><w:t xml:space=\"preserve\">C </w:t></w:r>`{=openxml}", |
| 68 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"></w:rPr><w:t xml:space=\"preserve\">Long Character</w:t></w:r>`{=openxml}" ) |
| 69 | + ) |
| 70 | +}) |
| 71 | + |
| 72 | +test_that("vector printing to console - character", { |
| 73 | + styled_vect <- |
| 74 | + color_vctr(c(TRUE, FALSE, TRUE, TRUE), |
| 75 | + text_color = c("red", "blue", "green", NA), |
| 76 | + style = c("bold","italic","strikethrough",NA), |
| 77 | + background = c("teal",NA,"yellow",NA)) |
| 78 | + |
| 79 | + expect_equal( |
| 80 | + capture_print(styled_vect), |
| 81 | + c("`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"darkCyan\"/><w:b/><w:color w:val=\"#FF0000\"/></w:rPr><w:t xml:space=\"preserve\"> TRUE</w:t></w:r>`{=openxml}", |
| 82 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:i/><w:color w:val=\"#0000FF\"/></w:rPr><w:t xml:space=\"preserve\">FALSE</w:t></w:r>`{=openxml}", |
| 83 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"yellow\"/><w:strike/><w:color w:val=\"#00FF00\"/></w:rPr><w:t xml:space=\"preserve\"> TRUE</w:t></w:r>`{=openxml}", |
| 84 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"></w:rPr><w:t xml:space=\"preserve\"> TRUE</w:t></w:r>`{=openxml}") |
| 85 | + ) |
| 86 | +}) |
| 87 | + |
| 88 | +test_that("vector printing to console - dates", { |
| 89 | + styled_vect <- |
| 90 | + color_vctr(as.Date(c("1970-01-01","1970-01-02","1970-01-03","1970-01-04")), |
| 91 | + text_color = c("red", "blue", "green", NA), |
| 92 | + style = c("bold","italic","strikethrough",NA), |
| 93 | + background = c("teal",NA,"yellow",NA)) |
| 94 | + |
| 95 | + expect_equal( |
| 96 | + capture_print(styled_vect), |
| 97 | + c("`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"darkCyan\"/><w:b/><w:color w:val=\"#FF0000\"/></w:rPr><w:t xml:space=\"preserve\">1970-01-01</w:t></w:r>`{=openxml}", |
| 98 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:i/><w:color w:val=\"#0000FF\"/></w:rPr><w:t xml:space=\"preserve\">1970-01-02</w:t></w:r>`{=openxml}", |
| 99 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"><w:highlight w:val=\"yellow\"/><w:strike/><w:color w:val=\"#00FF00\"/></w:rPr><w:t xml:space=\"preserve\">1970-01-03</w:t></w:r>`{=openxml}", |
| 100 | + "`<w:r><w:rPr xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"></w:rPr><w:t xml:space=\"preserve\">1970-01-04</w:t></w:r>`{=openxml}") |
| 101 | + ) |
| 102 | + |
| 103 | +}) |
| 104 | + |
| 105 | + |
0 commit comments