tests/testthat/test-file.R

test_that("handle filename", {
  fname <- Filename$new(name = "Indic.txt")
  expect_equal(fname$getExt(), ".txt")
  expect_equal(fname$changeExt(".csv"), "Indic.csv")
  expect_equal(fname$getFilenameSansExt(), "Indic")
  expect_equal(fname$getBasename(), "Indic.txt")
  expect_equal(fname$getDirname(), ".")
  expect_false(fname$exists())

  fname <- Filename$new(name = "/tmp/extdata/Indic.txt")
  expect_equal(fname$getExt(), ".txt")
  expect_equal(fname$changeExt(".csv"), "/tmp/extdata/Indic.csv")
  expect_equal(fname$getFilenameSansExt(), "/tmp/extdata/Indic")
  expect_equal(fname$getBasename(), "Indic.txt")
  expect_equal(fname$getDirname(), "/tmp/extdata")
  expect_false(fname$exists())

  fname <- Filename$new(name = "C:\\Temp\\extdata\\Indic.txt")
  expect_equal(fname$getExt(), ".txt")
  expect_equal(fname$changeExt(".csv"), "C:/Temp/extdata/Indic.csv")
  expect_equal(fname$getFilenameSansExt(), "C:/Temp/extdata/Indic")
  expect_equal(fname$getBasename(), "Indic.txt")
  expect_equal(fname$getDirname(), "C:/Temp/extdata")
  expect_false(fname$exists())

  expect_equal(
    fname$changeExt(".csv", "C:\\Temp\\inst\\extdata"),
    "C:/Temp/inst/extdata/Indic.csv"
  )
})

Try the rb3 package in your browser

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

rb3 documentation built on April 14, 2023, 5:10 p.m.