tests/testthat/test-parsing-count-fields.R

test_that("counts correct number of fields based on supplied tokenizer", {
  string <- "1,a,NA\n2,b,NA\n"
  res_csv <- count_fields(string, tokenizer_csv())
  res_tsv <- count_fields(string, tokenizer_tsv())
  expect_equal(res_csv, c(3, 3))
  expect_equal(res_tsv, c(1, 1))
})

test_that("maximum lines counted is respected", {
  string <- "1,a,NA\n2,b,NA\n"
  res_csv <- count_fields(string, tokenizer_csv(), n_max = 1)
  expect_equal(res_csv, 3)
})
tidyverse/readr documentation built on Jan. 27, 2024, 11:59 p.m.