tests/testthat/test-write.R

test_that("srt text files written from data frame", {
  skip_non_utf8()
  x <- read_srt(srt_example())
  p <- write_srt(x, tempfile(fileext = ".srt"))
  expect_true(file.exists(p))
  expect_error(read.csv(p))
  expect_error(readLines(p), NA)
})

test_that("non-srt files fail to write", {
  skip_non_utf8()
  expect_error(write_srt(1:3))
  expect_error(write_srt(letters))
  expect_error(write_srt(iris))
  x <- read_srt(srt_example())
  x[[2]] <- as.character(x[[2]])
  expect_error(write_srt(x))
  x <- read_srt(srt_example())
  x[[3]] <- as.character(x[[3]])
  expect_error(write_srt(x))
})

test_that("written lines match read lines exactly", {
  skip_non_utf8()
  skip_on_os("windows")
  x <- read_srt(srt_example(), collapse = "\n")
  p <- write_srt(x, tempfile(fileext = ".srt"), wrap = FALSE)
  expect_true(file.exists(p))
  a <- readLines(srt_example())
  b <- readLines(p)
  expect_equal(a, b)
})

Try the srt package in your browser

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

srt documentation built on Sept. 5, 2021, 5:28 p.m.