File: test-utils.R

package info (click to toggle)
r-cran-crul 1.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,620 kB
  • sloc: sh: 13; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,357 bytes parent folder | download
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
context("encode")
test_that("encode", {
  aa <- encode("https://httpbin.org")
  bb <- encode(I("https://httpbin.org"))

  expect_is(aa, "character")
  expect_is(bb, "AsIs")

  expect_match(aa, "%3A")
  expect_false(grepl("%3A", bb))
})


context("has_name")
test_that("has_name", {
  expect_false(has_name(5))
  expect_true(all(has_name(mtcars)))
  expect_true(has_name(list(a = 5)))
  expect_false(has_name(list(5)))
})


context("has_namez")
test_that("has_namez", {
  expect_false(has_namez(5))
  expect_true(has_namez(mtcars))
  expect_true(has_namez(list(a = 5)))
  expect_false(has_namez(list(5)))
})


context("make_query")
test_that("make_query", {
  aa <- make_query(list(foo = "hello", bar = "world"))

  expect_is(aa, "character")
  expect_match(aa, "foo")
  expect_match(aa, "&")
  expect_match(aa, "=")
})


context("curl_opts_check")
test_that("curl_opts_check works", {
  expect_null(curl_opts_check(verbose = TRUE))
  expect_null(curl_opts_check(timeout_ms = 0.001))
  expect_error(
    curl_opts_check(httppost = 1), "the following curl options are not allowed")
})

context("num_format")
test_that("num_format works", {
  expect_null(num_format(NULL))
  expect_equal(num_format(c("hello", "goodbye")),
               c("hello", "goodbye"))
  expect_equal(num_format(c(11, 0.00005, 200000)),
               c("11", "0.00005", "200000"))
})