Skip to content

Commit

Permalink
Tests/it extract path (#807)
Browse files Browse the repository at this point in the history
* Add additional tests for `check_it_reference()`

* Make the check on the IT reference stricter

* Update documentation

---------

Co-authored-by: Jennit07 <[email protected]>
Co-authored-by: Jennit07 <[email protected]>
  • Loading branch information
3 people authored Sep 26, 2023
1 parent a5bc79e commit b7ce1b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/get_it_extract_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-get_it_extract_paths.R
Original file line number Diff line number Diff line change
@@ -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", {
Expand Down

0 comments on commit b7ce1b1

Please sign in to comment.