1
1
testthat :: test_that(" eval_code evaluates the code in the qenvs environment" , {
2
2
q <- qenv()
3
- q1 <- eval_code(q , quote(iris1 <- iris ))
4
- q2 <- eval_code(q1 , quote(b <- nrow( iris1 ) ))
5
- testthat :: expect_identical (q2 $ b , 150L )
3
+ q1 <- eval_code(q , quote(a <- 1L ))
4
+ q2 <- eval_code(q1 , quote(b <- 1 ))
5
+ testthat :: expect_equal (q2 , list2env( list ( a = 1L , b = 1 )) )
6
6
})
7
7
8
8
testthat :: test_that(" eval_code locks the environment" , {
9
9
q <- eval_code(qenv(), quote(iris1 <- iris ))
10
- testthat :: expect_true(environmentIsLocked(q @ .xData ))
10
+ testthat :: expect_true(environmentIsLocked(q ))
11
11
})
12
12
13
13
testthat :: test_that(" eval_code doesn't have access to environment where it's called" , {
@@ -36,21 +36,29 @@ testthat::test_that("getting object from the package namespace works even if lib
36
36
testthat :: test_that(" eval_code works with character" , {
37
37
q1 <- eval_code(qenv(), " a <- 1" )
38
38
testthat :: expect_identical(get_code(q1 ), " a <- 1" )
39
- testthat :: expect_equal(q1 @ .xData , list2env(list (a = 1 )))
39
+ testthat :: expect_equal(q1 , list2env(list (a = 1 )))
40
40
})
41
41
42
42
testthat :: test_that(" eval_code works with expression" , {
43
- q1 <- eval_code(qenv(), as.expression(quote(a <- 1 )))
43
+ q1 <- eval_code(qenv(), expression(a <- 1 , b <- 2 ))
44
+ testthat :: expect_identical(get_code(q1 ), " a <- 1\n b <- 2" )
45
+ testthat :: expect_equal(q1 , list2env(list (a = 1 , b = 2 )))
46
+ })
44
47
45
- testthat :: expect_identical(get_code(q1 ), " a <- 1" )
46
- testthat :: expect_equal(q1 @ .xData , list2env(list (a = 1 )))
48
+ testthat :: test_that(" eval_code preserves original formatting when `srcref` is present in the expression" , {
49
+ code <- " # comment
50
+ a <- 1L"
51
+ expr <- parse(text = code , keep.source = TRUE )
52
+ q1 <- eval_code(qenv(), expr )
53
+ testthat :: expect_identical(get_code(q1 ), code )
54
+ testthat :: expect_equal(q1 , list2env(list (a = 1L )))
47
55
})
48
56
49
57
testthat :: test_that(" eval_code works with quoted" , {
50
58
q1 <- eval_code(qenv(), quote(a <- 1 ))
51
59
52
60
testthat :: expect_identical(get_code(q1 ), " a <- 1" )
53
- testthat :: expect_equal(q1 @ .xData , list2env(list (a = 1 )))
61
+ testthat :: expect_equal(q1 , list2env(list (a = 1 )))
54
62
})
55
63
56
64
testthat :: test_that(" eval_code works with quoted code block" , {
@@ -66,7 +74,7 @@ testthat::test_that("eval_code works with quoted code block", {
66
74
get_code(q1 ),
67
75
c(" a <- 1\n b <- 2" )
68
76
)
69
- testthat :: expect_equal(q1 @ .xData , list2env(list (a = 1 , b = 2 )))
77
+ testthat :: expect_equal(q1 , list2env(list (a = 1 , b = 2 )))
70
78
})
71
79
72
80
testthat :: test_that(" eval_code fails with unquoted expression" , {
@@ -172,3 +180,8 @@ testthat::test_that("comments passed alone to eval_code that contain @linksto ta
172
180
" x"
173
181
)
174
182
})
183
+
184
+ testthat :: test_that(" Code executed with integer shorthand (1L) is the same as original" , {
185
+ q <- within(qenv(), a <- 1L )
186
+ testthat :: expect_identical(get_code(q ), " a <- 1L" )
187
+ })
0 commit comments