-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathtest-sexp.cpp
More file actions
42 lines (33 loc) · 993 Bytes
/
test-sexp.cpp
File metadata and controls
42 lines (33 loc) · 993 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
38
39
40
41
42
#include "cpp11/list.hpp"
#include <testthat.h>
context("sexp-C++") {
test_that("sexp initializer lists work") {
using namespace cpp11::literals;
cpp11::writable::list out({
"int"_nm = {1, 2, 3},
"dbl"_nm = {1., 2., 3.},
"char"_nm = {"x", "y", "z"},
});
out.attr("class") = "data.frame";
out.attr("row.names") = {NA_INTEGER, -3};
expect_true(Rf_inherits(out, "data.frame"));
}
test_that("scalar constructors work") {
using namespace cpp11::literals;
cpp11::writable::list out({
"int"_nm = 1,
"dbl"_nm = 1.,
"char"_nm = "x",
});
out.attr("class") = "data.frame";
out.attr("row.names") = {NA_INTEGER, -1};
expect_true(Rf_inherits(out, "data.frame"));
}
test_that("move constructor works") {
using namespace cpp11::literals;
cpp11::sexp x(Rf_ScalarReal(5.));
cpp11::sexp y(std::move(x));
expect_true(SEXP(x) == R_NilValue);
expect_true(REAL(y)[0] == 5.);
}
}