Skip to content

Commit 172a023

Browse files
committed
Added Environment find() unit tests as well as a Symbol access test for Environment get().
1 parent 327d057 commit 172a023

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2016-11-19 James J Balamuta <[email protected]>
2+
3+
* inst/unitTests/runit.environments.R: Added environment find unit tests
4+
as well as a symbol access test for environment get.
5+
* inst/unitTests/cpp/Environment.cpp: Idem
6+
17
2016-11-16 Dirk Eddelbuettel <[email protected]>
28

39
* DESCRIPTION: Release 0.12.8

inst/NEWS.Rd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
\newcommand{\ghpr}{\href{https://github.com/RcppCore/Rcpp/pull/#1}{##1}}
44
\newcommand{\ghit}{\href{https://github.com/RcppCore/Rcpp/issues/#1}{##1}}
55

6+
\section{Changes in Rcpp version 0.12.9 (2017-01-xx)}{
7+
\item Changes in Rcpp unit tests
8+
\itemize{
9+
\item Added Environment::find unit tests and an Environment::get(Symbol)
10+
test (James Balamuta in \ghpr{595} addressing issue \ghit{594}).
11+
}
12+
}
613
\section{Changes in Rcpp version 0.12.8 (2016-11-16)}{
714
\itemize{
815
\item Changes in Rcpp API:

inst/unitTests/cpp/Environment.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ SEXP runit_get( Environment env, std::string name){
3737
return env.get( name ) ;
3838
}
3939

40+
// [[Rcpp::export]]
41+
SEXP runit_get_symbol( Environment env, Symbol name){
42+
return env.get( name ) ;
43+
}
44+
45+
// [[Rcpp::export]]
46+
SEXP runit_find( Environment env, std::string name){
47+
return env.find( name ) ;
48+
}
49+
50+
// [[Rcpp::export]]
51+
SEXP runit_find_symbol( Environment env, Symbol name){
52+
return env.find( name ) ;
53+
}
54+
4055
// [[Rcpp::export]]
4156
bool runit_exists( Environment env, std::string st){
4257
return env.exists( st ) ;

inst/unitTests/runit.environments.R

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,44 @@ if (.runThisTest) {
4343
e <- new.env( )
4444
e$a <- 1:10
4545
e$b <- "foo"
46-
47-
checkEquals( runit_get( e, "a" ), e$a, msg = "Environment::get()" )
48-
checkEquals( runit_get( e, "foobar" ), NULL, msg = "Environment::get()" )
46+
47+
# Access with string
48+
checkEquals( runit_get( e, "a" ), e$a, msg = "Environment::get(string)" )
49+
checkEquals( runit_get( e, "foobar" ), NULL, msg = "Environment::get(string)" )
4950
checkEquals( runit_get( asNamespace("Rcpp"), "CxxFlags"), Rcpp:::CxxFlags,
50-
msg = "Environment(namespace)::get() " )
51-
52-
}
53-
51+
msg = "Environment(namespace)::get(string) " )
52+
53+
# Access with Symbol constructed on call from string
54+
checkEquals( runit_get_symbol( e, "a" ), e$a, msg = "Environment::get(Symbol)" )
55+
checkEquals( runit_get_symbol( e, "foobar" ), NULL, msg = "Environment::get(Symbol)" )
56+
checkEquals( runit_get_symbol( asNamespace("Rcpp"), "CxxFlags"), Rcpp:::CxxFlags,
57+
msg = "Environment(namespace)::get(Symbol) " )
58+
59+
}
60+
61+
test.environment.find <- function(){
62+
e <- new.env( )
63+
e$a <- 1:10
64+
e$b <- "foo"
65+
bar <- "me"
66+
67+
# Access with string
68+
checkEquals( runit_find( e, "a" ), e$a, msg = "Environment::find(string)" )
69+
checkException( runit_find( e, "foobar" ), NULL, msg = "Environment::find(string) not found" )
70+
checkEquals( runit_find( e, "bar"), bar, msg = "Environment::find(string) inheritance" )
71+
checkEquals( runit_find( asNamespace("Rcpp"), "CxxFlags"), Rcpp:::CxxFlags,
72+
msg = "Environment(namespace)::find(string)" )
73+
74+
# Access with Symbol constructed on call from string
75+
checkEquals( runit_find_symbol( e, "a" ), e$a, msg = "Environment::find(Symbol)" )
76+
checkException( runit_find_symbol( e, "foobar" ), NULL, msg = "Environment::find(Symbol) not found" )
77+
checkEquals( runit_find_symbol( e, "bar"), bar, msg = "Environment::find(Symbol) inheritance" )
78+
checkEquals( runit_find_symbol( asNamespace("Rcpp"), "CxxFlags"), Rcpp:::CxxFlags,
79+
msg = "Environment(namespace)::find(Symbol)" )
80+
81+
}
82+
83+
5484
test.environment.exists <- function(){
5585
e <- new.env( )
5686
e$a <- 1:10

0 commit comments

Comments
 (0)