Skip to content

Commit

Permalink
fix: use newlines in code parseing on multiline expression with within
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Nov 1, 2024
1 parent c668d98 commit faa843b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions R/qenv-eval_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ setMethod("eval_code", signature = c("qenv", "character"), function(object, code
})

setMethod("eval_code", signature = c("qenv", "language"), function(object, code) {
eval_code(object, code = paste(vapply(lang2calls(code), deparse1, character(1)), collapse = "\n"))
eval_code(object, code = paste(vapply(lang2calls(code), deparse1, collapse = "\n", character(1L)), collapse = "\n"))
})

setMethod("eval_code", signature = c("qenv", "expression"), function(object, code) {
eval_code(object, code = paste(vapply(lang2calls(code), deparse1, character(1)), collapse = "\n"))
eval_code(object, code = paste(vapply(lang2calls(code), deparse1, collapse = "\n", character(1L)), collapse = "\n"))
})

setMethod("eval_code", signature = c("qenv.error", "ANY"), function(object, code) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-qenv_join.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ testthat::test_that("Joined qenv does not duplicate common code", {
q2 <- eval_code(q2, quote(mtcars2 <- mtcars))

testthat::expect_true(.check_joinable(q1, q2))
q <- join(q1, q2)
q <- c(q1, q2)

testthat::expect_identical(
q@code,
Expand Down
12 changes: 10 additions & 2 deletions tests/testthat/test-qenv_within.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ testthat::test_that("simple and compound expressions are evaluated", {
)
})

testthat::test_that("multiline expressions are evaluated", {
q <- qenv()
testthat::expect_no_error(
within(q, a <- function(x) {
y <- x + 1
y + 3
})
)
})

# code identity ----
testthat::test_that("styling of input code does not impact evaluation results", {
q <- qenv()
Expand Down Expand Up @@ -114,5 +124,3 @@ testthat::test_that("within run on qenv.error returns the qenv.error as is", {

testthat::expect_identical(qe, qee)
})

})

0 comments on commit faa843b

Please sign in to comment.