File: test-create.R

package info (click to toggle)
r-cran-bindrcpp 0.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208 kB
  • sloc: cpp: 141; ansic: 57; sh: 13; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 795 bytes parent folder | download | duplicates (3)
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
context("create")

test_that("cpp_create_environment()", {
  env <- cpp_create_environment(letters, "toupper")
  expect_equal(env$a, "A")
  expect_equal(env$x, "X")
  expect_null(env$X)
  expect_equal(length(ls(env)), length(letters))
  expect_error(env$a <- "a", "read-only")
})

test_that("cpp_create_environment() with inheritance", {
  env <- cpp_create_environment(letters, "toupper")
  env2 <- cpp_create_environment(LETTERS, "tolower", parent = env)
  expect_equal(get("a", env2), "A")
  expect_equal(get("x", env2), "X")
  expect_null(env2$a)
  expect_null(env2$x)
  expect_equal(env2$B, "b")
  expect_equal(env2$Y, "y")
  expect_equal(length(ls(env2)), length(letters))
  expect_error(env2$B <- "B", "read-only")
  expect_error(env2$a <- "a", NA)
  expect_equal(get("a", env2), "a")
})