tests/testthat/test_pngroup.R

context("pngroup")

test_that("pngroup works", {
  expect_null(pngroup(NULL, "a", 1))
  expect_null(pngroup("a", NULL, 1))
  expect_null(pngroup("a", "a", NULL))
  expect_null(pngroup("a", "a", NULL))
  expect_identical(pngroup("a", "a"), "a")
  expect_identical(pngroup("one two three", ".+\\s.+\\s.+", 1), "one two three")
  expect_identical(pngroup("one two three", ".+\\s.+\\s(.+)", 1), "one two three")
  expect_identical(pngroup("one two three", "(.+)\\s(.+)\\s(.+)", 4), "three")
  expect_identical(pngroup(c("one two three", "four five six"),
                           "(.+)\\s(.+)\\s(.+)", 2),
                   c("one", "four"))
  expect_identical(pngroup(c("one two three", "four five six"),
                           "(.+)\\s(.+)\\s(.+)", 2:4),
                   c("one", "five", "three"))
  expect_identical(pngroup("one two three",
                           c("(.+)\\s(.+)\\s(.+)", ".+\\s.+\\s.+"), 2),
                   c("one", NA))
})
avidclam/amxtra documentation built on May 17, 2019, 12:01 p.m.