tests/testthat/test_url.R

test_that("parsing and building URLs", {
  input <- "https://example.com/a%20path%20with%20spaces"
  actual <- build_url(parse_url(input))
  expected <- input
  expect_equal(actual, expected)

  input <- "https://example.com/a-path-without-spaces"
  actual <- build_url(parse_url(input))
  expected <- input
  expect_equal(actual, expected)
})

test_that("parse and build query strings", {
  # One parameter with a value, one without a value.
  input <- "bar=baz&foo="
  actual <- build_query_string(parse_query_string(input))
  expected <- input
  expect_equal(actual, expected)
})

test_that("missing query values become empty strings", {
  expect_equal(parse_query_string("?q="), list(q = ""))
  expect_equal(parse_query_string("?q"), list(q = ""))
  expect_equal(parse_query_string("?a&q"), list(a = "", q = ""))
})

test_that("empty queries become NULL", {
  expect_equal(parse_query_string("?"), list())
  expect_equal(parse_query_string(""), list())
})

Try the paws.common package in your browser

Any scripts or data that you put into this service are public.

paws.common documentation built on Sept. 11, 2024, 7 p.m.