File: test-cat-helpers.R

package info (click to toggle)
r-cran-cli 3.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,288 kB
  • sloc: ansic: 16,412; cpp: 37; sh: 13; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,202 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

test_that("cat_line", {
  expect_snapshot(
    cat_line("This is ", "a ", "line of text.")
  )

  tmp <- tempfile()
  on.exit(unlink(tmp), add = TRUE)
  cat_line("This is ", "a ", "line of text.", file = tmp)
  exp <- "This is a line of text."
  expect_equal(readLines(tmp, warn = FALSE), exp)

  local_reproducible_output(crayon = TRUE)

  expect_snapshot({
    cat_line("This is ", "a ", "line of text.", col = "red")
    cat_line("This is ", "a ", "line of text.", background_col = "green")
  })
})

test_that_cli(configs = c("plain", "unicode"), "cat_bullet", {
  expect_snapshot({
    cat_bullet(letters[1:5])
  })
})

test_that_cli(configs = c("plain", "unicode"), "cat_boxx", {
  expect_snapshot({
    cat_boxx("foo")
  })
})

test_that_cli(configs = c("plain", "unicode"), "cat_rule", {
  expect_snapshot(local({
    withr::local_options(cli.width = 20)
    cat_rule("title")
  }))
})

test_that_cli(configs = c("plain", "unicode"), "cat_print", {
  expect_snapshot({
    cat_print(boxx(""))
  })

  expect_snapshot(local({
    tmp <- tempfile()
    on.exit(unlink(tmp), add = TRUE)
    expect_silent(cat_print(boxx(""), file = tmp))
    cat(readLines(tmp, warn = FALSE), sep = "\n")
  }))
})