File: test-containers.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 (109 lines) | stat: -rw-r--r-- 2,441 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

start_app()
on.exit(stop_app(), add = TRUE)

test_that("auto closing", {
  expect_snapshot(local({
    cli_div(theme = list(".xx .emph" = list(before = "itsu:")))
    f <- function() {
      cli_par(class = "xx")
      cli_text("foo {.emph blah} bar")
    }

    # this has the marker
    f()
    # but this does not, because the .xx par was closed
    cli_text("foo {.emph blah} bar")
  }))
})

test_that("opt out of auto closing", {
  expect_snapshot(local({
    cli_div(theme = list(".xx .emph" = list(before = "itsu:")))
    id <- NULL
    f <- function() {
      id <<- cli_par(class = "xx", .auto_close = FALSE)
      cli_text("foo {.emph blah} bar")
    }

    f()

    # Still active
    cli_text("foo {.emph blah} bar")

    ## close explicitly
    expect_false(is.null(id))
    cli_end(id)
    cli_text("foo {.emph blah} bar")
  }))
})

test_that("auto closing with special env", {
  expect_snapshot(local({
    cli_div(theme = list(".xx .emph" = list(before = "itsu:")))
    f <- function() {
      g()
      # Still active
      cli_text("foo {.emph blah} bar")
    }

    g <- function() {
      cli_par(class = "xx", .auto_close = TRUE, .envir = parent.frame())
      cli_text("foo {.emph blah} bar")
    }

    f()

    # Not active any more
    cli_text("foo {.emph blah} bar")
  }))
})

test_that("div with special style", {
  expect_snapshot({
    f <- function() {
      cli_div(theme = list(".xx .emph" = list(before = "itsu:")))
      cli_par(class = "xx")
      cli_text("foo {.emph blah} bar")
    }
    f()
    # Not active any more
    cli_text("foo {.emph blah} bar")
  })
})

test_that("margin is squashed", {
  skip_if_not_installed("testthat", "3.1.2")

  # expect_snapshot cuts off the trailing newline from the message it
  # seems, so instead of 4 empty lines, there will be only three
  expect_snapshot(local({
    cli_div(theme = list(par = list("margin-top" = 4, "margin-bottom" = 4)))
    cli_text("three lines")
    cli_par()
    cli_par()
    cli_par()
    cli_text("until here")
    cli_end()
    cli_end()
    cli_end()
    cli_par()
    cli_par()
    cli_par()
    cli_text("no space, still")
    cli_end()
    cli_end()
    cli_end()
    cli_text("three lines again")
  }))
})

test_that("before and after work properly", {
  expect_snapshot(local({
    cli_div(
      theme = list(
        "div.alert-success" = list(before ="!!!")
      ))
    cli_alert_success("{.pkg foobar} is good")
  }))
})