File: test-assertions.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 (113 lines) | stat: -rw-r--r-- 2,834 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
110
111
112
113

test_that("is_string", {

  strings <- list("foo", "", "111", "1", "-", "NA")
  not_strings <- list(1, character(), NA_character_, NA,
                      c("foo", NA), c("1", "2"), NULL)

  for (p in strings) {
    expect_true(is_string(p))
    expect_silent(stopifnot(is_string(p)))
  }

  for (n in not_strings) {
    expect_false(is_string(n))
    expect_error(
      stopifnot(is_string(n)),
      "is_string(n) is not TRUE",
      fixed = TRUE
    )
  }
})

test_that("is_border_style", {
  expect_true(is_border_style(rownames(box_styles())[1]))
  expect_false(is_border_style("blahblahxxx"))

  expect_silent(stopifnot(is_border_style(rownames(box_styles())[1])))
  expect_error(
    stopifnot(is_border_style("blahblahxxx")),
    "is_border_style(\"blahblahxxx\") is not TRUE",
    fixed = TRUE
  )
})

test_that("is_padding_or_margin", {
  good <- list(1, 0, 0L, 1L, 237, c(1,2,3,4), c(0,0,0,0), rep(1L, 4))
  bad <- list(numeric(), integer(), c(1,2), c(1L, 2L, 3L), 1:5,
              "1", c("1", "2", "3", "1"), NA, NA_real_, NA_integer_,
              c(1,2,NA,1), c(1L,NA,3L))

  for (g in good) {
    expect_true(is_padding_or_margin(g))
    expect_silent(stopifnot(is_padding_or_margin(g)))
  }
  for (b in bad) {
    expect_false(is_padding_or_margin(b))
    expect_error(
      stopifnot(is_padding_or_margin(b)),
      "is_padding_or_margin(b) is not TRUE",
      fixed = TRUE
    )
  }
})

test_that("is_col", {
  good <- list("red", "orange", NULL, col_red)
  bad <- list(c("red", "orange"), character(), NA_character_)

  for (g in good) {
    expect_true(is_col(g))
    expect_silent(stopifnot(is_col(g)))
  }
  for (b in bad) {
    expect_false(is_col(b))
    expect_error(
      stopifnot(is_col(b)),
      "is_col(b) is not TRUE",
      fixed = TRUE
    )
  }
})

test_that("is_count", {

  counts <- list(1, 1L, 0, 0L, 42, 42L)
  not_counts <- list(c(1, 2), numeric(), NA_integer_, NA_real_, NA, 1.1,
                     NULL, "1")

  for (c in counts) {
    expect_true(is_count(c))
    expect_silent(stopifnot(is_count(c)))
  }

  for (n in not_counts) {
    expect_false(is_count(n))
    expect_error(
      stopifnot(is_count(n)),
      "is_count(n) is not TRUE",
      fixed = TRUE
    )
  }
})

test_that("is_tree_style", {
  good <- list(
    list(h = "1", v = "2", l = "3", j = "4"),
    list(j = "4", v = "2", h = "1", l = "3")
  )
  bad <- list(
    NULL,
    1:4,
    c(h = "1", v = "2", l = "3", j = "4"),
    list(h = "1", v = "2", l = "3", j = "4", x = "10"),
    list(h = "1", v = c("2", "3"), l = "3", j = "4"),
    list(h = "1", v = "2", l = character(), j = "4"),
    list(h = "1", v = "2", l = 3, j = "4"),
    list("1", v = "2", l = "3", j = "4"),
    list("1", "2", "3", "4")
  )

  for (x in good) expect_true (is_tree_style(x))
  for (x in bad ) expect_false(is_tree_style(x))
})