Debian Codegraph @

tests/testthat/test-url.R

raw
1 test_that("Query string parsing", {
2 expect_identical(
3 parseQueryString("?foo=1&bar=b+a%20r&b+a%20z=baz&=nokey&novalue=&=&noequal&end=end"),
4 list(
5 foo = '1',
6 bar = 'b a r',
7 `b a z` = 'baz',
8 'nokey',
9 novalue = '',
10 '',
11 noequal = '',
12 end = 'end'
13 )
14 )
15
16 # Should be the same with or without leading question mark
17 expect_identical(parseQueryString("?foo=1&bar=b"), parseQueryString("foo=1&bar=b"))
18
19 # Leading/trailing/consecutive ampersands are ignored
20 expect_identical(parseQueryString("?&a=1&&b=2&"), parseQueryString("?a=1&b=2"))
21
22 # Nested and non-nested query strings
23 expect_identical(
24 parseQueryString("a[i1][j1]=x&b[i1][j1]=y&b[i2][j1]=z"),
25 list(
26 "a[i1][j1]" = "x",
27 "b[i1][j1]" = "y",
28 "b[i2][j1]" = "z"
29 )
30 )
31
32 expect_identical(
33 parseQueryString("a[i1][j1]=x&b[i1][j1]=y&b[i2][j1]=z", nested = TRUE),
34 list(
35 a = list(i1 = list(j1 = "x")),
36 b = list(
37 i1 = list(j1 = "y"),
38 i2 = list(j1 = "z")
39 )
40 )
41 )
42 })