| 1 |
test_that("rowids for line-style", { |
| 2 |
lines <- function(char = "-") { |
| 3 |
stopifnot(nchar(char) == 1) |
| 4 |
structure(char, class = "lines") |
| 5 |
} |
| 6 |
|
| 7 |
format_lines <- function(x, width, ...) { |
| 8 |
paste(rep(x, width), collapse = "") |
| 9 |
} |
| 10 |
|
| 11 |
ctl_new_pillar_line_tbl <- function(controller, x, width, ..., title = NULL) { |
| 12 |
out <- NextMethod() |
| 13 |
new_pillar(list( |
| 14 |
title = out$title, |
| 15 |
type = out$type, |
| 16 |
lines = new_pillar_component(list(lines("=")), width = 1), |
| 17 |
data = out$data |
| 18 |
)) |
| 19 |
} |
| 20 |
|
| 21 |
ctl_new_rowid_pillar_line_tbl <- function(controller, x, width, ...) { |
| 22 |
out <- NextMethod() |
| 23 |
new_pillar( |
| 24 |
list( |
| 25 |
title = out$title, |
| 26 |
type = out$type, |
| 27 |
lines = new_pillar_component(list(lines("=")), width = 1), |
| 28 |
data = out$data |
| 29 |
), |
| 30 |
width = as.integer(floor(log10(max(nrow(x), 1))) + 1) |
| 31 |
) |
| 32 |
} |
| 33 |
|
| 34 |
local_methods( |
| 35 |
format.lines = format_lines, |
| 36 |
ctl_new_pillar.line_tbl = ctl_new_pillar_line_tbl, |
| 37 |
ctl_new_rowid_pillar.line_tbl = ctl_new_rowid_pillar_line_tbl |
| 38 |
) |
| 39 |
|
| 40 |
expect_snapshot({ |
| 41 |
vctrs::new_data_frame( |
| 42 |
list(a = 1:3, b = letters[1:3]), |
| 43 |
class = c("line_tbl", "tbl") |
| 44 |
) |
| 45 |
}) |
| 46 |
}) |
| 47 |
|
| 48 |
test_that("roman rowids", { |
| 49 |
ctl_new_rowid_pillar_roman_tbl <- function(controller, x, width, ...) { |
| 50 |
out <- NextMethod() |
| 51 |
rowid <- utils::as.roman(seq_len(nrow(x))) |
| 52 |
width <- max(nchar(as.character(rowid))) |
| 53 |
new_pillar( |
| 54 |
list( |
| 55 |
title = out$title, |
| 56 |
type = out$type, |
| 57 |
data = pillar_component( |
| 58 |
new_pillar_shaft(list(row_ids = rowid), |
| 59 |
width = width, |
| 60 |
class = "pillar_rif_shaft" |
| 61 |
) |
| 62 |
) |
| 63 |
), |
| 64 |
width = width |
| 65 |
) |
| 66 |
} |
| 67 |
|
| 68 |
local_methods( |
| 69 |
ctl_new_rowid_pillar.roman_tbl = ctl_new_rowid_pillar_roman_tbl |
| 70 |
) |
| 71 |
|
| 72 |
expect_snapshot({ |
| 73 |
vctrs::new_data_frame( |
| 74 |
list(a = 1:3, b = letters[1:3]), |
| 75 |
class = c("roman_tbl", "tbl") |
| 76 |
) |
| 77 |
}) |
| 78 |
}) |