File: test-utils.R

package info (click to toggle)
r-cran-stringr 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,112 kB
  • sloc: javascript: 11; sh: 9; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 776 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
test_that("keep_names() returns logical flag based on inputs", {
  expect_true(keep_names("a", "x"))
  expect_false(keep_names("a", c("x", "y")))
  expect_true(keep_names(c("a", "b"), "x"))
  expect_true(keep_names(c("a", "b"), c("x", "y")))
})

test_that("copy_names() applies names to vectors if present", {
  expect_equal(
    copy_names(c(A = "a", B = "b"), c("x", "y")),
    c(A = "x", B = "y")
  )

  expect_equal(
    copy_names(c("a", "b"), c("x", "y")),
    c("x", "y")
  )
})

test_that("copy_names() applies rownames to matrices if present", {
  from <- c(A = "a", B = "b")
  to <- matrix(c("x", "y"), nrow = 2)

  expected <- to
  rownames(expected) <- names(from)

  expect_equal(copy_names(from, to), expected)
  expect_equal(copy_names(c("a", "b"), to), to)
})