diff --git a/R/parse-query.R b/R/parse-query.R index ade461bd4..832e93f89 100644 --- a/R/parse-query.R +++ b/R/parse-query.R @@ -184,26 +184,7 @@ combine_keys <- function(obj, type) { function(x) { unname(unlist(x)) }, - "multi" = - function(x) { - if (length(x) == 1) { - # return first item only - return(x[[1]]) - } - - # return list of internal named items - # aka... unlist the top layer only. Maintain the inner layer names - x_new <- lapply(unname(x), function(x_item) { - if (is.atomic(x_item)) { - # handles things like `parse_text` which returns atomic values - return(list(x_item)) - } - - # handles things like `parse_octet` which returns a (possibly) named list - x_item - }) - as.list(unlist(x_new, recursive = FALSE)) - } + stop("unknown type: ", type) ) # equivalent code output, `split` is much faster with larger objects diff --git a/tests/testthat/test-combine-keys.R b/tests/testthat/test-combine-keys.R deleted file mode 100644 index 123d3dce3..000000000 --- a/tests/testthat/test-combine-keys.R +++ /dev/null @@ -1,109 +0,0 @@ -context("combine keys") - -test_that("query keys with same name are combined", { - a <- list(A = 1, A = 2, B = 3, A = 4, B = 5) - expect_equal(combine_keys(a, "query"), list(A = c(1,2,4), B = c(3,5))) -}) - -test_that("multi part keys with same name are combined", { - # no lists - a <- list(A = 1, A = 2, B = 3, A = 4, B = 5) - expect_equal(combine_keys(a, "multi"), list(A = list(1,2,4), B = list(3,5))) - - # unnamed lists - a <- list(A = 1, A = list(11,12), B = 3, A = 4, B = 5) - expect_equal(combine_keys(a, "multi"), list(A = list(1,11,12,4), B = list(3,5))) - - # partial named lists - a <- list(A = 1, A = list(X = 11,12), B = 3, A = list(Y = 4), B = 5) - expect_equal(combine_keys(a, "multi"), list(A = list(1,X = 11, 12, Y = 4), B = list(3,5))) - - # named lists - a <- list(A = 1, A = list(X = 11, Y = 12), B = 3, A = list(Z = 4), B = 5) - expect_equal(combine_keys(a, "multi"), list(A = list(1,X = 11, Y = 12, Z = 4), B = list(3,5))) -}) - - -test_that("multi part keys with no name are left alone", { - a <- list(A = 1, 2, A = 3, B = 4, 5) - expect_equal(combine_keys(a, "multi"), list(A = list(1,3), B = 4, 2, 5)) - - a <- list(A = 1, 2, A = 3, B = 4, 5) - expect_equal(combine_keys(a, "multi"), list(A = list(1,3), B = 4, 2, 5)) - a <- list(A = 1, 2, A = 3, B = 4, 5) - expect_equal(combine_keys(a, "multi"), list(A = list(1,3), B = 4, 2, 5)) -}) - - -test_that("multi part keys with no names are untouched", { - a <- list(1,2,3,4,5) - expect_equal(combine_keys(a, "multi"), a) - - a <- list(1,list(2),3,4,5) - expect_equal(combine_keys(a, "multi"), a) - - a <- list(1,list(2),3,list(4,5)) - expect_equal(combine_keys(a, "multi"), a) - - a <- list(list(1),list(2),list(3),list(4, 5)) - expect_equal(combine_keys(a, "multi"), a) -}) - -test_that("multi part keys with all same name", { - a <- list(A = 1, A = 2, A = 3, A = 4, A = 5) - expect_equal(combine_keys(a, "multi"), list(A = list(1,2,3,4,5))) - - a <- list(A = 1,A = list(2),A = 3,A = 4,A = 5) - expect_equal(combine_keys(a, "multi"), list(A = list(1,2,3,4,5))) - - a <- list(A = 1,A = list(2),A = 3,A = list(4,5)) - expect_equal(combine_keys(a, "multi"), list(A = list(1,2,3,4,5))) - - a <- list(A = 1,A = list(2),A = 3,A = list(4,Y = 5)) - expect_equal(combine_keys(a, "multi"), list(A = list(1,2,3,4,Y = 5))) - - a <- list(A = 1,A = list(2),A = 3,A = list(X = 4,Y = 5)) - expect_equal(combine_keys(a, "multi"), list(A = list(1,2,3,X = 4,Y = 5))) - - a <- list(A = 1,A = list(B = 2),A = 3,A = list(X = 4,Y = 5)) - expect_equal(combine_keys(a, "multi"), list(A = list(1,B = 2,3,X = 4,Y = 5))) -}) - - -test_that("raw values are not combined", { - x <- charToRaw("testval") - y <- charToRaw("other testval") - - a <- list(x,y) - expect_equal(combine_keys(a, "multi"), list(x, y)) - - a <- list(A = x,y) - expect_equal(combine_keys(a, "multi"), list(A = x, y)) - - a <- list(A = x, B = y) - expect_equal(combine_keys(a, "multi"), list(A = x, B = y)) - - a <- list(A = x, A = y) - expect_equal(combine_keys(a, "multi"), list(A = list(x, y))) - - a <- list(A = list(X = x), A = y) - a <- list(A = list(X = x), A = list(y)) - expect_equal(combine_keys(a, "multi"), list(A = list(X = x, y))) - - a <- list(A = list(x), A = list(Y = y)) - expect_equal(combine_keys(a, "multi"), list(A = list(x, Y = y))) - - a <- list(A = list(X = x), A = list(Y = y)) - expect_equal(combine_keys(a, "multi"), list(A = list(X = x, Y = y))) - - - a <- list(A = list(X = x), A = list(Y = y), A = "foobar") - expect_equal(combine_keys(a, "multi"), list(A = list(X = x, Y = y, "foobar"))) -}) - - -test_that("inner list structures are preserved", { - - a <- list(A = 1, B = 2, A = list(X = 3, Y = 4)) - expect_equal(combine_keys(a, "multi"), list(A = list(1,X = 3, Y = 4), B = 2)) -}) diff --git a/tests/testthat/test-querystring.R b/tests/testthat/test-querystring.R index 8c8268f5b..34bef06fd 100644 --- a/tests/testthat/test-querystring.R +++ b/tests/testthat/test-querystring.R @@ -70,3 +70,8 @@ test_that("different lengths of query string return same shape", { } }) + +test_that("query keys with same name are combined", { + a <- list(A = 1, A = 2, B = 3, A = 4, B = 5) + expect_equal(combine_keys(a, "query"), list(A = c(1,2,4), B = c(3,5))) +})