1test_that("sanity check (1)", { 2 expect_false(crayon::has_color()) 3 expect_equal(crayon::num_colors(), 1) 4 expect_false(has_color()) 5 expect_equal(num_colors(), 1) 6 7 expect_snapshot({ 8 crayon::has_color() 9 crayon::num_colors() 10 has_color() 11 num_colors() 12 style_na("NA") 13 }) 14}) 15 16test_that("output test", { 17 x <- list( 18 column_zero_one = 1:3 + 0.23, 19 col_02 = letters[1:3], 20 col_03 = factor(letters[1:3]), 21 col_04 = ordered(letters[1:3]) 22 ) 23 expect_snapshot({ 24 colonnade(x, width = 4) 25 colonnade(x, width = 5) 26 colonnade(x, width = 6) 27 colonnade(x, width = 7) 28 colonnade(x, width = 8) 29 colonnade(x, width = 9) 30 colonnade(x, width = 10) 31 colonnade(x, width = 11) 32 colonnade(x, width = 12) 33 colonnade(x, width = 13) 34 colonnade(x, width = 14) 35 colonnade(x, width = 15) 36 colonnade(x, width = 16) 37 colonnade(x, width = 17) 38 colonnade(x, width = 18) 39 colonnade(x, width = 19) 40 colonnade(x, width = 20) 41 colonnade(x, width = 21) 42 colonnade(x, width = 22) 43 colonnade(x, width = 23) 44 colonnade(x, width = 24) 45 colonnade(x, width = 25) 46 colonnade(x, width = 26) 47 colonnade(x, width = 27) 48 colonnade(x, width = 28) 49 colonnade(x, width = 29) 50 colonnade(x, width = 30) 51 colonnade(x, width = 31) 52 colonnade(x, width = 32) 53 colonnade(x, width = 33) 54 colonnade(x, width = 34) 55 colonnade(x, width = 35) 56 colonnade(x, width = 36) 57 colonnade(x, width = 37) 58 colonnade(x, width = 38) 59 colonnade(x, width = 39) 60 colonnade(x, width = Inf) 61 }) 62 63 expect_snapshot({ 64 colonnade(rep(list(paste(letters, collapse = " ")), 4), width = Inf) 65 }) 66 67 # Spurious warnings on Windows 68 suppressWarnings( 69 expect_snapshot({ 70 new_vertical(extra_cols_impl(squeeze_impl(colonnade(x), width = 10))) 71 }) 72 ) 73 74 suppressWarnings( 75 expect_snapshot({ 76 new_vertical(extra_cols_impl(squeeze_impl(colonnade(x), width = 20))) 77 }) 78 ) 79 80 suppressWarnings( 81 expect_snapshot({ 82 new_vertical(extra_cols_impl(squeeze_impl(colonnade(x), width = 30))) 83 }) 84 ) 85 86 suppressWarnings( 87 expect_snapshot({ 88 new_vertical(extra_cols_impl(squeeze_impl(colonnade(x), width = 35))) 89 }) 90 ) 91 92 expect_snapshot({ 93 new_vertical(extra_cols_impl(squeeze_impl(colonnade(x), width = 40))) 94 }) 95}) 96 97test_that("tests from tibble", { 98 skip_if_not_installed("rlang", "0.4.11.9000") 99 local_options(width = 80) 100 101 expect_snapshot({ 102 colonnade(mtcars[1:8, ], has_row_id = "*", width = 30) 103 colonnade(iris[1:5, ], width = 30) 104 colonnade(iris[1:3, ], width = 20) 105 colonnade(df_all, width = 30) 106 colonnade(df_all, width = 300) 107 options(width = 70) 108 colonnade(df_all, width = 300) 109 options(width = 60) 110 colonnade(df_all, width = 300) 111 options(width = 50) 112 colonnade(df_all, width = 300) 113 options(width = 40) 114 colonnade(df_all, width = 300) 115 options(width = 30) 116 colonnade(df_all, width = 300) 117 options(width = 20) 118 colonnade(df_all, width = 300) 119 colonnade(list(`\n` = c("\n", '"'), `\r` = factor("\n")), width = 30) 120 colonnade(list(a = c("", " ", "a ", " a")), width = 30) 121 colonnade(list("mean(x)" = 5, "var(x)" = 3), width = 30) 122 }) 123}) 124 125test_that("empty", { 126 expect_equal( 127 format(colonnade(list(a = character(), b = logical()), width = 30)), 128 structure(character(), class = "pillar_vertical") 129 ) 130 expect_equal( 131 format(colonnade(iris[1:5, character()], width = 30)), 132 structure(character(), class = "pillar_vertical") 133 ) 134}) 135 136test_that("NA names", { 137 x <- list(`NA` = 1:3, set_to_NA = 4:6) 138 names(x)[[2]] <- NA_character_ 139 expect_snapshot({ 140 colonnade(x, width = 30) 141 }) 142}) 143 144test_that("sep argument", { 145 x <- list(sep = 1:3) 146 expect_snapshot({ 147 colonnade(x, width = 30) 148 "dummy" 149 }) 150}) 151 152# Run opposite test to snapshot output but not alter it 153if (!l10n_info()$`UTF-8`) { 154 test_that("color, options: UTF-8 is TRUE", { 155 skip("Symmetry") 156 }) 157} 158 159test_that(paste0("color, options: UTF-8 is ", l10n_info()$`UTF-8`), { 160 local_colors() 161 expect_true(crayon::has_color()) 162 expect_equal(crayon::num_colors(), 16) 163 expect_true(has_color()) 164 expect_equal(num_colors(), 16) 165 166 if (l10n_info()$`UTF-8`) { 167 local_utf8() 168 expect_true(cli::is_utf8_output()) 169 } 170 171 expect_snapshot({ 172 crayon::has_color() 173 crayon::num_colors() 174 has_color() 175 num_colors() 176 style_na("NA") 177 style_neg("-1") 178 }) 179 180 expect_snapshot({ 181 style_na("NA") 182 }) 183 184 xf <- colonnade(list(x = c((10^(-3:4)) * c(-1, 1), NA))) 185 186 expect_snapshot({ 187 print(xf) 188 with_options(pillar.subtle_num = TRUE, print(xf)) 189 with_options(pillar.subtle = FALSE, print(xf)) 190 with_options(pillar.neg = FALSE, print(xf)) 191 with_options(pillar.subtle = FALSE, pillar.neg = FALSE, print(xf)) 192 with_options(pillar.bold = TRUE, print(xf)) 193 }) 194 195 expect_snapshot({ 196 colonnade(list(a_very_long_column_name = 0), width = 15) 197 }) 198}) 199 200# Run opposite test to snapshot output but not alter it 201if (l10n_info()$`UTF-8`) { 202 test_that("color, options: UTF-8 is FALSE", { 203 skip("Symmetry") 204 }) 205} 206 207test_that("sanity check (2)", { 208 expect_false(crayon::has_color()) 209 expect_equal(crayon::num_colors(), 1) 210 expect_false(has_color()) 211 expect_equal(num_colors(), 1) 212 213 expect_snapshot({ 214 crayon::has_color() 215 crayon::num_colors() 216 has_color() 217 num_colors() 218 style_na("NA") 219 }) 220}) 221 222test_that("tibble columns", { 223 x <- list(a = 1:3, b = data.frame(c = 4:6, d = 7:9)) 224 expect_snapshot({ 225 colonnade(x, width = 30) 226 }) 227}) 228 229test_that("tibble columns (nested)", { 230 x <- list( 231 a = 1:3, 232 b = structure( 233 list( 234 c = 4:6, d = 7:9, 235 e = data.frame(f = 10:12, g = 13:15) 236 ), 237 class = "data.frame" 238 ) 239 ) 240 expect_snapshot({ 241 colonnade(x, width = 40) 242 }) 243}) 244 245test_that("tibble columns (empty)", { 246 x <- list( 247 a = 1:3, 248 b = structure( 249 list( 250 c = 4:6, d = 7:9, 251 e = data.frame(f = 10:12)[, 0], 252 f = 10:12 253 ), 254 class = "data.frame" 255 ) 256 ) 257 expect_snapshot({ 258 colonnade(x, width = 40) 259 }) 260}) 261 262test_that("matrix columns (unnamed)", { 263 x <- list(a = 1:3, b = matrix(4:9, ncol = 2)) 264 expect_snapshot({ 265 colonnade(x, width = 30) 266 }) 267}) 268 269test_that("matrix columns (named)", { 270 x <- list(a = 1:3, b = matrix(4:9, ncol = 2, dimnames = list(NULL, c("c", "d")))) 271 expect_snapshot({ 272 colonnade(x, width = 30) 273 }) 274}) 275 276test_that("matrix columns (empty)", { 277 x <- list(a = 1:3, b = matrix(4:6, ncol = 1)[, 0], c = 4:6) 278 expect_snapshot({ 279 colonnade(x, width = 30) 280 }) 281}) 282