tests/testthat/test-write-ps1.R

test_that("PowerShell scripts are written in UTF-8 with a BOM", {
  path <- tempfile(fileext = ".ps1")
  doconv:::write_ps1(c('$indocx = "C:\\tmp\\\u6d4b\u8bd5.docx"', "Write-Output $indocx"), path)
  bytes <- readBin(path, "raw", file.size(path))

  expect_identical(bytes[1:3], as.raw(c(0xef, 0xbb, 0xbf)))
  # the path is kept in UTF-8
  expect_identical(
    rawToChar(bytes[-(1:3)]),
    '$indocx = "C:\\tmp\\\u6d4b\u8bd5.docx"\r\nWrite-Output $indocx\r\n'
  )
})

Try the doconv package in your browser

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

doconv documentation built on Oct. 22, 2026, 5:14 p.m.