Skip to content

Commit 198ecb3

Browse files
authored
Merge pull request #1237 from RcppCore/feature/coerce-unit-tests
add small unit test for coerce
2 parents 4015d89 + 9b2a18f commit 198ecb3

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2022-10-27 Kevin Ushey <[email protected]>
2+
3+
* inst/tinytest/cpp/coerce.cpp: add coerce unit tests
4+
* inst/tinytest/test_coerce.R: idem
5+
16
2022-10-12 Dirk Eddelbuettel <[email protected]>
27

38
* DESCRIPTION (Version, Date): Roll minor version

inst/tinytest/cpp/coerce.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2+
//
3+
// coerce.cpp: Rcpp R/C++ interface class library -- coerce unit tests
4+
//
5+
// Copyright (C) 2022 Dirk Eddelbuettel and Kevin Ushey
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
22+
#include <Rcpp.h>
23+
using namespace Rcpp ;
24+
25+
// [[Rcpp::export]]
26+
std::string coerce_raw_to_string(Rbyte x) {
27+
return internal::coerce_to_string<RAWSXP>(x);
28+
}

inst/tinytest/test_coerce.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
## Copyright (C) 2022 Dirk Eddelbuettel and Kevin Ushey
3+
##
4+
## This file is part of Rcpp.
5+
##
6+
## Rcpp is free software: you can redistribute it and/or modify it
7+
## under the terms of the GNU General Public License as published by
8+
## the Free Software Foundation, either version 2 of the License, or
9+
## (at your option) any later version.
10+
##
11+
## Rcpp is distributed in the hope that it will be useful, but
12+
## WITHOUT ANY WARRANTY; without even the implied warranty of
13+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
## GNU General Public License for more details.
15+
##
16+
## You should have received a copy of the GNU General Public License
17+
## along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
18+
19+
if (Sys.getenv("RunAllRcppTests") != "yes") exit_file("Set 'RunAllRcppTests' to 'yes' to run.")
20+
21+
Rcpp::sourceCpp("cpp/coerce.cpp")
22+
23+
expect_equal(coerce_raw_to_string(0xaa), "aa")

0 commit comments

Comments
 (0)