1show_output_in_terminal <- function() {
2  system2("xterm", c("-e", shQuote("head tests/testthat/out/*; sleep 600")))
3}
4
5# A data frame with all major types
6df_all <- pillar:::new_tbl(list(
7  a = c(1, 2.5, NA),
8  b = c(1:2, NA),
9  c = c(T, F, NA),
10  d = c("a", "b", NA),
11  e = factor(c("a", "b", NA)),
12  f = as.Date("2015-12-09") + c(1:2, NA),
13  g = as.POSIXct("2015-12-09 10:51:34.5678", tz = "UTC") + c(1:2, NA),
14  h = as.list(c(1:2, NA)),
15  i = list(list(1, 2:3), list(4:6), list(NA))
16))
17
18# A data frame with strings of varying lengths
19long_str <- strrep("Abcdefghij", 5)
20df_str <- pillar:::map(rlang::set_names(1:50), function(i) substr(long_str, 1, i))
21
22#' `add_special()` is not exported, and used only for initializing default
23#' values to `expect_pillar_output()`.
24#' @rdname expect_pillar_output
25add_special <- function(x) {
26  if (inherits(x, "integer64")) {
27    x <- c(x, bit64::NA_integer64_)
28  } else {
29    x <- x[seq2(1, length(x) + 1)]
30    if (is.numeric(x) && is.double(x)) {
31      x <- c(x, -Inf, Inf)
32    }
33  }
34  x
35}
36
37continue <- function(x) {
38  paste0(x, cli::symbol$continue)
39}
40
41# from pkgdepends
42local_colors <- function(.local_envir = parent.frame()) {
43  # This is to restore crayon's cache. This runs after restoring the options.
44  withr::defer(envir = .local_envir, {
45    crayon::num_colors(forget = TRUE)
46    num_colors(forget = TRUE)
47  })
48
49  # We run this first, so this will run last by withr, to restore the
50  # original options.
51  withr::local_options(
52    list(crayon.enabled = TRUE, cli.num_colors = 16L),
53    .local_envir = .local_envir
54  )
55
56  # Added safety
57  crayon::num_colors(forget = TRUE)
58  num_colors(forget = TRUE)
59}
60
61local_utf8 <- function(enable = TRUE, .local_envir = parent.frame()) {
62  withr::local_options(
63    list(cli.unicode = enable),
64    .local_envir = .local_envir
65  )
66}
67