This file is indexed.

/usr/share/doc/r-cran-rlang/tests/testthat/test-s3.R is in r-cran-rlang 0.2.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
context("s3")

test_that("inherits from all classes", {
  x <- structure(list(), class = c("foo", "bar", "baz"))

  expect_true(inherits_all(x, c("foo")))
  expect_true(inherits_all(x, c("foo", "baz")))
  expect_true(inherits_all(x, c("foo", "bar", "baz")))

  expect_false(inherits_all(x, c("fooz")))
  expect_false(inherits_all(x, c("foo", "barz", "baz")))
  expect_false(inherits_all(x, c("fooz", "bar", "baz")))

  expect_error(inherits_all(x, chr()), "empty")
})

test_that("inherits from any class", {
  x <- structure(list(), class = "bar")

  expect_true(inherits_any(x, c("bar", "foo")))
  expect_true(inherits_any(x, c("foo", "bar")))
  expect_true(inherits_any(x, c("foo", "bar", "baz")))

  expect_false(inherits_any(x, c("foo", "baz")))

  expect_error(inherits_any(x, chr()), "empty")
})

test_that("inherits only from class", {
  x <- structure(list(), class = c("foo", "bar", "baz"))
  expect_false(inherits_only(x, c("foo", "baz")))
  expect_true(inherits_only(x, c("foo", "bar", "baz")))
})

test_that("can box and unbox a value", {
  box <- new_box(letters, "foo")
  expect_true(is_box(box))
  expect_true(is_box(box), "foo")
  expect_false(is_box(box, "bar"))
  expect_identical(unbox(box), letters)

  box <- new_box(NULL, c("foo", "bar", "baz"))
  expect_true(is_box(box, c("foo", "baz")))
  expect_false(is_box(box, c("baz", "foo")))
})

test_that("as_box() ensures boxed value", {
  box <- as_box(NULL)
  expect_true(inherits_only(box, "rlang_box"))

  boxbox <- as_box(box)
  expect_true(inherits_only(box, "rlang_box"))
  expect_null(unbox(box))

  some_box <- as_box(NULL, "some_box")
  some_boxbox <- as_box(some_box, "other_box")
  expect_true(inherits_only(some_boxbox, c("other_box", "rlang_box")))
  expect_true(inherits_only(unbox(some_boxbox), c("some_box", "rlang_box")))
  expect_null(unbox(unbox(some_boxbox)))
})

test_that("as_box_if() ensures boxed value if predicate returns TRUE", {
  box <- as_box_if(NULL, is_null, "null_box")
  expect_true(inherits_only(box, c("null_box", "rlang_box")))

  boxbox <- as_box_if(box, is_null, "null_box")
  expect_true(inherits_only(box, c("null_box", "rlang_box")))
  expect_null(unbox(boxbox))

  expect_null(as_box_if(NULL, is_vector, "null_box"))
})

test_that("unboxing a non-boxed value is an error", {
  expect_error(unbox(NULL), "must be a box")
})