Skip to content

Commit

Permalink
Merge 04206b4 into 1edbe47
Browse files Browse the repository at this point in the history
  • Loading branch information
clarabicalho committed May 24, 2018
2 parents 1edbe47 + 04206b4 commit 71d0ef1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 14 additions & 3 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ get_design_code <- function(design){
construct_design_code <- function(designer, args){
# get the code for the design
txt <- as.character(getSrcref(designer))

open <- grep("[{]{3}", txt)
close <- grep("[}]{3}", txt)
if(length(txt)==0){
txt <- deparse(designer)
x <- grep("^[[:blank:]]*[{]", txt)
open <- x[which(diff(x) == 1)]
if(length(open)>3) stop("More than three consecutive `{` found in ", substitute(designer))
open <- max(open)+1
x <- grep("^[[:blank:]]*[}]", txt)
close <- x[which(diff(x) == 1)]
if(length(close)>2) stop("More than three consecutive `}` found in ", substitute(designer))
close <- min(close)
}else{
open <- grep("[{]{3}", txt)
close <- grep("[}]{3}", txt)
}

if(length(open) != 1) stop("could not find opening tag in ", substitute(designer))
if(length(close) != 1) stop("could not find opening tag in ", substitute(designer))
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test_designers.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ for(designer in designers){
expect_true(any(grepl("declare_design|/",design_attr$code)))
})

testthat::test_that(
desc = paste0(designer, "'s default design code runs without errors"),
code = {
expect_error(eval(parse(text = get_design_code(one_design))), NA)
})

testthat::test_that(
desc = paste0("Code inside ",designer, " runs and creates an appropriately named design object."),
code = {
Expand Down

0 comments on commit 71d0ef1

Please sign in to comment.