forked from r-lib/httr2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-utils-multi.R
More file actions
70 lines (63 loc) · 1.68 KB
/
test-utils-multi.R
File metadata and controls
70 lines (63 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
test_that("can handle multi query params", {
expect_equal(
multi_dots(a = 1:2, .multi = "explode"),
list(a = I("1"), a = I("2"))
)
expect_equal(
multi_dots(a = 1:2, .multi = "comma"),
list(a = I("1,2"))
)
expect_equal(
multi_dots(a = 1:2, .multi = "pipe"),
list(a = I("1|2"))
)
expect_equal(
multi_dots(a = 1:2, .multi = function(x) "X"),
list(a = I("X"))
)
})
test_that("can handle mixed length multi query params", {
expect_equal(
multi_dots(a = 1:2, b = 1, c = NULL, .multi = "explode"),
list(a = I("1"), a = I("2"), b = I("1"), c = NULL)
)
expect_equal(
multi_dots(a = 1:2, b = 1, c = NULL, .multi = "comma"),
list(a = I("1,2"), b = I("1"), c = NULL)
)
expect_equal(
multi_dots(a = 1:2, b = 1, c = NULL, .multi = "pipe"),
list(a = I("1|2"), b = I("1"), c = NULL)
)
expect_equal(
multi_dots(a = 1:2, b = 1, c = NULL, .multi = function(x) "X"),
list(a = I("X"), b = I("1"), c = NULL)
)
})
test_that("can opt-out of escaping for' vectors", {
expect_equal(
multi_dots(a = I(c(" ", " ")), .multi = "comma"),
list(a = I(" , "))
)
})
test_that("can handle empty dots", {
expect_equal(multi_dots(), list())
})
test_that("preserves NULL values", {
expect_equal(multi_dots(x = NULL), list(x = NULL))
})
test_that("preserves duplicates values", {
expect_equal(multi_dots(x = 1, x = 2), list(x = I("1"), x = I("2")))
})
test_that("leaves already escaped values alone", {
x <- I("1 + 2")
expect_equal(multi_dots(x = x), list(x = x))
})
test_that("checks its inputs", {
expect_snapshot(error = TRUE, {
multi_dots(1)
multi_dots(x = I(1))
multi_dots(x = 1:2)
multi_dots(x = mean)
})
})