File: test-ansi-utils.R

package info (click to toggle)
r-cran-cli 3.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,288 kB
  • sloc: ansic: 16,412; cpp: 37; sh: 13; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,458 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
52
53
54
55
56
57
58

test_that("re_table", {
  withr::local_options(
    cli.num_colors = 256,
    cli.hyperlink = TRUE
  )
  txt <- paste0(
    "this is some text ",
    col_red("red"),
    " some more text ",
    col_green("green"),
    " then some ",
    style_hyperlink("text", "https://example.com")
  )
  tbl <- re_table(ansi_regex(), txt)[[1]]
  tbl2 <- cbind(tbl, c(text = substring(txt, tbl[, "start"], tbl[, "end"])))
  expect_snapshot(tbl2)
  expect_snapshot(non_matching(list(tbl), txt))
})

test_that("re_table special cases", {
  withr::local_options(
    cli.num_colors = 256,
    cli.hyperlink = TRUE
  )
  txt <- "foobar"
  tbl <- re_table(ansi_regex(), txt)[[1]]
  expect_snapshot(tbl)
  expect_snapshot(non_matching(list(tbl), txt))
  expect_snapshot(non_matching(list(tbl), txt, empty = TRUE))

  txt <- col_red("foobar")
  tbl <- re_table(ansi_regex(), txt)[[1]]
  expect_snapshot(tbl)
  expect_snapshot(non_matching(list(tbl), txt))
  expect_snapshot(non_matching(list(tbl), txt, empty = TRUE))

  txt <- paste0("foo ", col_red(""), " bar")
  tbl <- re_table(ansi_regex(), txt)[[1]]
  expect_snapshot(tbl)
  expect_snapshot(non_matching(list(tbl), txt))
  expect_snapshot(non_matching(list(tbl), txt, empty = TRUE))
})

test_that("myseq", {
  expect_snapshot({
    myseq(1, 5)
    myseq(1, 1)
    myseq(1, 0)
    myseq(1, 5, 2)
    myseq(1, 6, 2)
    myseq(1, 1, 2)
    myseq(1, 2, -1)
    myseq(10, 1, -1)
    myseq(10, 1, -2)
    myseq(1, 5, -2)
  })
})