From 5f75564e9e20fb50cdfe8500f2577fed07081a4e Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Sat, 15 Jul 2023 16:40:18 -0500 Subject: [PATCH] incorporate another test scenario from @BlairCooper ref #504 @BlairCooper wrote https://github.com/OuhscBbmc/REDCapR/pull/502/files --- NEWS.md | 2 +- tests/testthat/test-metadata-utilities.R | 31 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index f5877ae2..76dba7c4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -89,7 +89,7 @@ This will help extract forms from longitudinal & repeating projects. * `validate_repeat_instance()` * `validate_no_logical()` * `redcap_read()` checks the `event` parameter and throws an error if a value is not recognized, or the project is not longitudinal (#493) -* The regex in `regex_named_captures()` is forgiving if there's an unnecessary leading space (@BlairCooper, #495) +* The regex in `regex_named_captures()` is forgiving if there's an unnecessary leading space (@BlairCooper, #495, #501) Version 1.1.0 (released 2022-08-10) ========================================================== diff --git a/tests/testthat/test-metadata-utilities.R b/tests/testthat/test-metadata-utilities.R index 4b7e9744..6ceed0f3 100644 --- a/tests/testthat/test-metadata-utilities.R +++ b/tests/testthat/test-metadata-utilities.R @@ -110,6 +110,37 @@ test_that("checkbox choices -commas in labels", { expect_equal(ds_expected, label = "no trailing spaces:") }) +test_that("checkbox choices -digits only", { + ds_expected <- # datapasta::tribble_paste(ds_expected) + tibble::tribble( + ~id , ~label, + "1" , "1", + "2" , "2", + "3" , "3", + "4" , "4" + ) + + # well-behaved + "1, 1 | 2, 2 | 3, 3 | 4, 4" |> + checkbox_choices() |> + expect_equal(ds_expected, label = "well-behaved:") + + # missing leading space + "1, 1 | 2,2 | 3, 3 | 4, 4" |> + checkbox_choices() |> + expect_equal(ds_expected, label = "missing leading space:") + + # missing trailing spaces + "1, 1 | 2, 2| 3, 3| 4, 4" |> + checkbox_choices() |> + expect_equal(ds_expected, label = "no leading spaces:") + + # extra lines + "|1, 1 | 2, 2 | 3, 3 || 4, 4| |" |> + checkbox_choices() |> + expect_equal(ds_expected, label = "well-behaved:") +}) + test_that("checkbox choices with special characters", { ds_expected <- # datapasta::tribble_paste(ds_expected) tibble::tribble(