File: test-spec.R

package info (click to toggle)
r-cran-lifecycle 1.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 576 kB
  • sloc: sh: 15; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,406 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
test_that("spec() builds feature data", {
  expect_identical(
    spec("foo()"),
    spec_data(fn = "foo")
  )
  expect_identical(
    spec("pkg::foo()"),
    spec_data(fn = "foo", pkg = "pkg")
  )

  expect_identical(
    spec("foo(bar)"),
    spec_data(fn = "foo", arg = "bar")
  )
  expect_identical(
    spec("foo(bar = )"),
    spec_data(fn = "foo", arg = "bar")
  )
  expect_identical(
    spec("pkg::foo(bar = )"),
    spec_data(fn = "foo", arg = "bar", pkg = "pkg")
  )

  expect_identical(
    spec("foo(bar = 'baz')"),
    spec_data(fn = "foo", arg = "bar", reason = "baz")
  )
  expect_identical(
    spec("pkg::foo(bar = 'baz')"),
    spec_data(fn = "foo", arg = "bar", pkg = "pkg", reason = "baz")
  )
})

test_that("spec() gives useful errors", {
  expect_snapshot(spec(1), error = TRUE)
  expect_snapshot(spec("foo"), error = TRUE)
  expect_snapshot(spec("foo()()"), error = TRUE)
  expect_snapshot(spec("foo(arg = , arg = )"), error = TRUE)
  expect_snapshot(spec("foo(arg = arg)"), error = TRUE)

  e <- new_environment()
  local_options(topLevelEnvironment = e)
  expect_snapshot(spec("foo()", env = e), error = TRUE)
})

test_that("spec() works with methods", {
  expect_identical(
    spec("A$foo()"),
    spec_data(fn = "A$foo")
  )
  expect_identical(
    spec("A$foo(bar = )"),
    spec_data(fn = "A$foo", arg = "bar")
  )

  expect_snapshot(spec("A$foo(bar = 1)"), error = TRUE)
})