diff --git a/tests/testthat/test-indexing.R b/tests/testthat/test-indexing.R index 0cc7612..1573a27 100644 --- a/tests/testthat/test-indexing.R +++ b/tests/testthat/test-indexing.R @@ -1,6 +1,6 @@ context("roomba indexing tests") -test_that("", { +test_that("Test that dfs_idx() works as expected", { twitter_data <- twitter_data x <- dfs_idx(twitter_data, ~ .x$id_str == "998623997397876743") diff --git a/tests/testthat/test-roomba.R b/tests/testthat/test-roomba.R new file mode 100644 index 0000000..b9d3d11 --- /dev/null +++ b/tests/testthat/test-roomba.R @@ -0,0 +1,28 @@ +context("roomba tests") + +library(jsonlite) + +test_that("Test that roomba() works as expected", { + + some_json <- '{ + "foo": [{"a": 1, "b": 2, "c": 3}], + "bar": [{"a": 4, "c": 6, "b": null}], + "baz": [], + "bing":[{"c": 12}] + }' + + lst <- fromJSON(some_json) + + expect_equal(roomba(lst, cols = c("a", "b", "c")), + data.frame(a = c(1, 4), b = c(2, NA), c = c(3, 6))) + + expect_equal(roomba(lst, cols = c("a", "b", "c"), keep = any), + data.frame(a = c(1, 4, NA), b = c(2, NA, NA), c = c(3, 6, 12))) + + expect_error(roomba(lst, cols = character()), + regexp = "Argument 1 must have names") + + expect_error(roomba(lst), + regexp = "cols must be non-NULL.") + +}) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 1aba875..fa0ef0b 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -6,7 +6,7 @@ library(dplyr) test_that("Test that replace_null() works as expected", { # Test that replace_null() works as expected lst <- list(c("a", "b"), x = NULL) - cleaned_lst <- roomba:::replace_null(lst, replacement = "foo") + cleaned_lst <- replace_null(lst, replacement = "foo") expect_equal(cleaned_lst, list(c("a", "b"), x = "foo")) }) @@ -49,17 +49,17 @@ test_that("Test that replace_null() works with numbers", { }', simplifyVector = FALSE) - cleaned_lst <- roomba:::replace_null(toy_data) + cleaned_lst <- replace_null(toy_data) secret_power <- cleaned_lst %>% dfs_idx(~ .x$goodstuff == "here") %>% - purrr:::map_dfr(~ cleaned_lst[[.x]]) %>% - dplyr::pull(secret_power) + map_dfr(~ cleaned_lst[[.x]]) %>% + pull(secret_power) expect_type(secret_power, "integer") toy_names <- cleaned_lst %>% dfs_idx(~ .x$goodstuff == "here") %>% - purrr:::map_dfr(~ cleaned_lst[[.x]]) %>% - dplyr::pull(name) + map_dfr(~ cleaned_lst[[.x]]) %>% + pull(name) expect_type(toy_names, "character")