forked from r-lib/cpp11
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-environment.cpp
More file actions
37 lines (27 loc) · 845 Bytes
/
test-environment.cpp
File metadata and controls
37 lines (27 loc) · 845 Bytes
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
#include "cpp11/as.hpp"
#include "cpp11/environment.hpp"
#include "cpp11/function.hpp"
#include "cpp11/strings.hpp"
#include <testthat.h>
context("environment-C++") {
test_that("environment works") {
auto new_env = cpp11::package("base")["new.env"];
SEXP x_sxp = PROTECT(new_env());
cpp11::environment x(x_sxp);
expect_true(x.size() == 0);
x["foo"] = 1;
expect_true(x.size() == 1);
expect_true(cpp11::as_cpp<int>(x["foo"]) == 1);
x["bar"] = "hi";
expect_true(x.size() == 2);
expect_true(cpp11::strings(x["bar"])[0] == "hi");
x.remove("bar");
expect_true(x.size() == 1);
expect_true(x["bar"] == R_UnboundValue);
x.remove("foo");
expect_true(x.size() == 0);
expect_true(x["foo"] == R_UnboundValue);
expect_true(static_cast<SEXP>(x) == x_sxp);
UNPROTECT(1);
}
}