File: test-complain.R

package info (click to toggle)
r-cran-lazyeval 0.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 596 kB
  • sloc: ansic: 310; sh: 9; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 947 bytes parent folder | download | duplicates (4)
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
context("complain")

test_that("NULL return unchanged", {
  expect_identical(complain(NULL), NULL)
})

test_that("can't access non-existent list members", {
  x1 <- list(y = 1)
  x2 <- complain(x1)

  expect_equal(x2$y, 1)
  expect_error(x2$z, "object 'z' not found")
  expect_error(x2[["z"]], "object 'z' not found")
})

test_that("can't access non-existent environment components", {
  x1 <- list2env(list(y = 1))
  x2 <- complain(x1)

  expect_equal(x2$y, 1)
  expect_error(x2$z, "object 'z' not found")
  expect_error(x2[["z"]], "object 'z' not found")
})

test_that("can't use non-character vectors", {
  x <- complain(list(y = 1))

  expect_error(x[[1]], "subset with a string")
  expect_error(x[[c("a", "b")]], "subset with a string")
})

test_that("complain doesn't taint env class", {
  x1 <- list2env(list(y = 1))
  x2 <- complain(x1)

  expect_equal(class(x1), "environment")
  expect_equal(class(x2), c("complain", "environment"))

})