|
1 | | -testthat::test_that("`[.` returns empty qenv for names not in qenv", { |
| 1 | +testthat::test_that("`[.` warns and subsets to empty if all names not present in env nor code", { |
2 | 2 | data <- within(qenv(), { |
3 | | - x <- 1 |
4 | | - a <- 2 |
| 3 | + a <- 1 |
| 4 | + b <- 2 |
5 | 5 | }) |
6 | 6 | testthat::expect_warning( |
7 | | - testthat::expect_equal(data["y"], qenv()), |
| 7 | + testthat::expect_equal(data[c("y", "z")], qenv()), |
| 8 | + "Object\\(s\\) not found in code: y, z." |
| 9 | + ) |
| 10 | + testthat::expect_warning( |
| 11 | + testthat::expect_equal(data[c("y", "z")], qenv()), |
8 | 12 | "None of 'names' exist in the environment of the 'qenv'. Returning empty 'qenv." |
9 | 13 | ) |
10 | 14 | }) |
11 | 15 |
|
12 | | -testthat::test_that("`[.` returns limited qenv for some names not in qenv", { |
| 16 | +testthat::test_that("`[.` warns and subsets to empty if all names not present in env", { |
13 | 17 | data <- within(qenv(), { |
14 | | - x <- 1 |
15 | | - a <- 2 |
| 18 | + a <- 1 |
| 19 | + b <- 2 |
| 20 | + c <- 3 |
| 21 | + rm(b, c) |
16 | 22 | }) |
17 | 23 | testthat::expect_warning( |
18 | | - testthat::expect_equal(data[c("y", "a")], data["a"]), |
19 | | - "Some elements of 'names' do not exist in the environment of the 'qenv'. Skipping those: y." |
| 24 | + testthat::expect_equal(data[c("b", "c")], qenv()), |
| 25 | + "None of 'names' exist in the environment of the 'qenv'. Returning empty 'qenv'." |
20 | 26 | ) |
21 | 27 | }) |
22 | 28 |
|
23 | | -testthat::test_that("`[.` limits code for some names not in code", { |
| 29 | +testthat::test_that("`[.` warns and subsets to existing if some names not present in env and code", { |
24 | 30 | data <- within(qenv(), { |
25 | | - x <- 1 |
26 | | - a <- 2 |
27 | | - rm(x) |
| 31 | + a <- 1 |
| 32 | + b <- 2 |
28 | 33 | }) |
29 | 34 | testthat::expect_warning( |
30 | | - testthat::expect_equal(data[c("a", "x")], data["a"]), |
31 | | - "Some elements of 'names' do not exist in the environment of the 'qenv'. Skipping those: x." |
| 35 | + testthat::expect_equal(data[c("b", "c", "d")], data["b"]), |
| 36 | + "Some elements of 'names' do not exist in the environment of the 'qenv'. Skipping those: c, d." |
| 37 | + ) |
| 38 | + testthat::expect_warning( |
| 39 | + testthat::expect_equal(data[c("b", "c", "d")], data["b"]), |
| 40 | + "Object\\(s\\) not found in code: c, d." |
32 | 41 | ) |
33 | 42 | }) |
34 | 43 |
|
35 | | - |
36 | 44 | testthat::test_that("`[.` subsets environment and code to specified object names", { |
37 | 45 | q <- qenv() |
38 | 46 | code <- c("x<-1", "a<-1;b<-2") |
@@ -64,16 +72,3 @@ testthat::test_that("`[.` comments are preserved in the code and associated with |
64 | 72 | c("x<-1 #comment\n", "a<-1;") |
65 | 73 | ) |
66 | 74 | }) |
67 | | - |
68 | | -testthat::test_that("`[.` extract proper elements of @id, @warnings and @messages fiels", { |
69 | | - q <- qenv() |
70 | | - code <- |
71 | | - c("x<-1 #comment", "message('tiny message')", "a<-1;b<-2;warning('small warning')") |
72 | | - q <- eval_code(q, code) |
73 | | - qs <- q[c("x", "a")] |
74 | | - |
75 | | - testthat::expect_identical(get_code_attr(qs, "id"), get_code_attr(q, "id")[c(1, 3)]) |
76 | | - testthat::expect_identical(unlist(qs@code), unlist(q@code[c(1, 3)])) |
77 | | - testthat::expect_null(get_code_attr(qs, "warning")) |
78 | | - testthat::expect_null(get_code_attr(qs, "message")) |
79 | | -}) |
0 commit comments