File: test-call.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 (44 lines) | stat: -rw-r--r-- 1,321 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
40
41
42
43
44
context("call")

# Creation ----------------------------------------------------------------

test_that("character vector must be length 1", {
  expect_error(call_new(letters), "must be length 1")
})

test_that("args can be specified individually or as list", {
  out <- call_new("f", a = 1, .args = list(b = 2))
  expect_equal(out, quote(f(a = 1, b = 2)))
})

# Standardisation ---------------------------------------------------------

test_that("can standardise base function", {
  out <- call_standardise(quote(matrix(nro = 3, 1:9)))
  expect_equal(out, quote(matrix(data = 1:9, nrow = 3)))
})

test_that("can standardise local function", {
  foo <- function(bar, baz) {}
  out <- call_standardise(quote(foo(baz = 1, 4)))
  expect_equal(out, quote(foo(bar = 4, baz = 1)))
})

# Modification ------------------------------------------------------------

test_that("all args must be named", {
  call <- quote(matrix(1:10))
  expect_error(call_modify(call, list(1)), "must be named")
})

test_that("new args inserted at end", {
  call <- quote(matrix(1:10))
  out <- call_modify(call, list(nrow = 3))
  expect_equal(out, quote(matrix(data = 1:10, nrow = 3)))
})

test_that("new args replace old", {
  call <- quote(matrix(1:10))
  out <- call_modify(call, list(data = 3))
  expect_equal(out, quote(matrix(data = 3)))
})