| 1 |
test_that("promise_map handles NULL values", { |
| 2 |
prom2_map <- function(first_res, second_res) { |
| 3 |
f <- function(index) { |
| 4 |
switch(index, first_res, second_res) |
| 5 |
} |
| 6 |
promise_map(1:2, f) |
| 7 |
} |
| 8 |
|
| 9 |
counter <- 0 |
| 10 |
|
| 11 |
prom2_map("anything", "anything_else") |> |
| 12 |
then(\(x) { |
| 13 |
counter <<- counter + 1 |
| 14 |
expect_equal(x, list("anything", "anything_else")) |
| 15 |
}) |> |
| 16 |
wait_for_it() |
| 17 |
|
| 18 |
prom2_map(NULL, "anything_else") |> |
| 19 |
then(\(x) { |
| 20 |
counter <<- counter + 1 |
| 21 |
expect_equal(x, list(NULL, "anything_else")) |
| 22 |
}) |> |
| 23 |
wait_for_it() |
| 24 |
|
| 25 |
prom2_map("anything", NULL) |> |
| 26 |
then(\(x) { |
| 27 |
counter <<- counter + 1 |
| 28 |
expect_equal(x, list("anything", NULL)) |
| 29 |
}) |> |
| 30 |
wait_for_it() |
| 31 |
|
| 32 |
prom2_map(NULL, NULL) |> |
| 33 |
then(\(x) { |
| 34 |
counter <<- counter + 1 |
| 35 |
expect_equal(x, list(NULL, NULL)) |
| 36 |
}) |> |
| 37 |
wait_for_it() |
| 38 |
|
| 39 |
expect_equal(counter, 4) |
| 40 |
}) |