Skip to content

Commit 2e82c12

Browse files
additional ✅ for #849
1 parent 714a017 commit 2e82c12

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

inst/unitTests/cpp/Vector.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Vector.cpp: Rcpp R/C++ interface class library -- Vector unit tests
44
//
5-
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2018 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -848,3 +848,10 @@ String vec_print_integer(IntegerVector v) {
848848
IntegerVector vec_subset(IntegerVector x, IntegerVector y) {
849849
return x[y - 1];
850850
}
851+
852+
// [[Rcpp::export]]
853+
int CharacterVectorNoProtect(Vector<STRSXP, NoProtectStorage> s){
854+
s[0] = "";
855+
return s.size();
856+
}
857+

inst/unitTests/runit.Vector.R

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env r
22
# hey emacs, please make this use -*- tab-width: 4 -*-
33
#
4-
# Copyright (C) 2010 - 2015 Dirk Eddelbuettel and Romain Francois
4+
# Copyright (C) 2010 - 2018 Dirk Eddelbuettel and Romain Francois
55
#
66
# This file is part of Rcpp.
77
#
@@ -499,7 +499,7 @@ if (.runThisTest) {
499499
paste(letters, collapse=""),
500500
msg = "CharacterVector::iterator using std::accumulate" )
501501
}
502-
502+
503503
test.CharacterVector.iterator <- function(){
504504
fun <- character_const_iterator1
505505
checkEquals(fun(letters),
@@ -655,12 +655,12 @@ if (.runThisTest) {
655655
res <- character_vector_const_proxy( "fooo" )
656656
checkEquals( res, "fooo", msg = "CharacterVector const proxy. #32" )
657657
}
658-
658+
659659
test.CharacterVector.test.const.proxy <- function(){
660660
res <- CharacterVector_test_const_proxy( letters )
661661
checkEquals( res, letters )
662662
}
663-
663+
664664
test.sort <- function() {
665665
num <- setNames( c(1, -1, 4, NA, 5, NaN), letters[1:5] )
666666
checkIdentical( sort_numeric(num), sort(num, na.last=TRUE) )
@@ -671,33 +671,33 @@ if (.runThisTest) {
671671
lgcl <- as.logical(int)
672672
checkIdentical( sort_logical(lgcl), sort(lgcl, na.last=TRUE) )
673673
}
674-
674+
675675
test.sort_desc <- function() {
676676
num <- setNames(c(1, -1, 4, NA, 5, NaN), letters[1:5])
677677
checkIdentical(
678-
sort_numeric_desc(num),
678+
sort_numeric_desc(num),
679679
sort(num, decreasing = TRUE, na.last = FALSE)
680680
)
681-
681+
682682
int <- as.integer(num)
683683
checkIdentical(
684-
sort_integer_desc(int),
685-
sort(int, decreasing = TRUE, na.last = FALSE)
684+
sort_integer_desc(int),
685+
sort(int, decreasing = TRUE, na.last = FALSE)
686686
)
687-
687+
688688
char <- setNames(sample(letters, 5), LETTERS[1:5])
689689
checkIdentical(
690-
sort_character_desc(char),
691-
sort(char, decreasing = TRUE, na.last = FALSE)
690+
sort_character_desc(char),
691+
sort(char, decreasing = TRUE, na.last = FALSE)
692692
)
693-
693+
694694
lgcl <- as.logical(int)
695695
checkIdentical(
696-
sort_logical_desc(lgcl),
697-
sort(lgcl, decreasing = TRUE, na.last = FALSE)
696+
sort_logical_desc(lgcl),
697+
sort(lgcl, decreasing = TRUE, na.last = FALSE)
698698
)
699699
}
700-
700+
701701
test.List.assign.SEXP <- function() {
702702
l <- list(1, 2, 3)
703703
other <- list_sexp_assign(l)
@@ -711,12 +711,12 @@ if (.runThisTest) {
711711
test.logical.vector.from.bool.assign <- function() {
712712
checkIdentical(logical_vector_from_bool_assign(), TRUE)
713713
}
714-
714+
715715
test.noprotect_vector <- function(){
716716
x <- rnorm(10)
717717
checkIdentical( noprotect_vector(x), 10L )
718718
}
719-
719+
720720
test.noprotect_matrix <- function(){
721721
x <- matrix(rnorm(10), nrow=2)
722722
checkIdentical( noprotect_matrix(x), 2L )
@@ -755,5 +755,11 @@ if (.runThisTest) {
755755
gctorture(FALSE)
756756
checkEquals(x[y], z)
757757
}
758+
759+
test.CharacterVectorNoProtect <- function(){
760+
s <- "foo"
761+
checkEquals(CharacterVectorNoProtect(s), 1L)
762+
checkEquals(s, "")
763+
}
758764
}
759765

0 commit comments

Comments
 (0)