From b7ce1b158e27d1407571b1404ff4c6ea295033ad Mon Sep 17 00:00:00 2001 From: James McMahon Date: Tue, 26 Sep 2023 11:53:44 +0100 Subject: [PATCH] Tests/it extract path (#807) * Add additional tests for `check_it_reference()` * Make the check on the IT reference stricter * Update documentation --------- Co-authored-by: Jennit07 Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/get_it_extract_paths.R | 2 +- tests/testthat/test-get_it_extract_paths.R | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/R/get_it_extract_paths.R b/R/get_it_extract_paths.R index 2c587e93b..3c4dc54c3 100644 --- a/R/get_it_extract_paths.R +++ b/R/get_it_extract_paths.R @@ -107,7 +107,7 @@ check_it_reference <- function(it_reference) { it_reference <- stringr::str_sub(it_reference, start = 7L, end = 14L) } - if (stringr::str_detect(it_reference, "[0-9]{7}", negate = TRUE)) { + if (stringr::str_detect(it_reference, "^[0-9]{7}$", negate = TRUE)) { cli::cli_abort( c("x" = "{.arg it_reference} must be exactly 7 numbers."), call = rlang::caller_env() diff --git a/tests/testthat/test-get_it_extract_paths.R b/tests/testthat/test-get_it_extract_paths.R index baaad52a5..52f9e4181 100644 --- a/tests/testthat/test-get_it_extract_paths.R +++ b/tests/testthat/test-get_it_extract_paths.R @@ -1,3 +1,25 @@ +test_that("IT reference cleanup works", { + expect_equal(check_it_reference("SCTASK0439133"), "0439133") + expect_equal(check_it_reference("0439133"), "0439133") + + expect_error( + check_it_reference("123456789"), + "`it_reference` must be exactly 7 numbers\\." + ) + expect_error( + check_it_reference("1234567890"), + "`it_reference` must be exactly 7 numbers\\." + ) + expect_error( + check_it_reference("SCTASK123456789"), + "`it_reference` must be exactly 7 numbers\\." + ) + expect_error( + check_it_reference("ABCDEF123456789"), + "`it_reference` must be exactly 7 numbers\\." + ) +}) + skip_on_ci() test_that("IT extract file paths work", {