tests/testthat/test-encoding.R

library(hipread)

context("Encodings work")

test_that("latin1 and utf-8 match", {
  expect_equal(
    hipread_long(
      hipread_example("test-enc-latin1.dat"),
      hip_fwf_widths(
        c(3, 3),
        c("v1", "v2"),
        c("character", "integer")
      ),
      encoding = "latin1"
    ),
    hipread_long(
      hipread_example("test-enc-utf8.dat"),
      hip_fwf_widths(
        c(3, 3),
        c("v1", "v2"),
        c("character", "integer")
      ),
      encoding = "UTF-8"
    )
  )
})

test_that("skip bom in utf-8 bom", {
  expect_equal(
    hipread_long(
      hipread_example("test-enc-utf8.dat"),
      hip_fwf_widths(
        c(3, 3),
        c("v1", "v2"),
        c("character", "integer")
      ),
      encoding = "UTF-8"
    ),
    hipread_long(
      hipread_example("test-enc-utf8bom.dat"),
      hip_fwf_widths(
        c(3, 3),
        c("v1", "v2"),
        c("character", "integer")
      ),
      encoding = "UTF-8"
    )

  )
})

Try the hipread package in your browser

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

hipread documentation built on Sept. 30, 2022, 5:08 p.m.