From b23a8df1af7bb890f253ce46e137103460e36a9f Mon Sep 17 00:00:00 2001 From: Leonidas Zhak <70497898+LeonidasZhak@users.noreply.github.com> Date: Sat, 6 Jun 2026 21:06:35 +0800 Subject: [PATCH] test: add test for format.sas trailing period stripping in XPT roundtrip --- tests/testthat/test-haven-sas.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/testthat/test-haven-sas.R b/tests/testthat/test-haven-sas.R index cdd83b8e..95610409 100644 --- a/tests/testthat/test-haven-sas.R +++ b/tests/testthat/test-haven-sas.R @@ -304,6 +304,21 @@ test_that("can roundtrip format attribute", { expect_identical(df, out) }) +test_that("trailing period in format.sas is stripped during roundtrip", { + df <- tibble( + date_var = structure(as.Date("2025-01-02"), format.sas = "DATE9."), + num_var = structure(100.12345, format.sas = "BEST12.") + ) + + path <- tempfile() + write_xpt(df, path) + out <- read_xpt(path) + + # SAS transport format does not store trailing periods + expect_equal(attr(out$date_var, "format.sas"), "DATE9") + expect_equal(attr(out$num_var, "format.sas"), "BEST12") +}) + test_that("user width warns appropriately when data is wider than value", { df <- tibble( a = c("a", NA_character_),