Skip to content

Commit

Permalink
1 subject test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tdhock committed Aug 15, 2024
1 parent aa1c5de commit 3325b53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/apply_type_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ apply_type_funs <- function
if(1 < length(dup.type.tab)){
stop(domain=NA, gettextf("capture groups with identical names should have conversion functions that all return the same type; problem group name=%s has types %s", dup.name, paste(names(dup.type.tab), collapse = ",")))
}
is.match.name <- is.match[, dup.col.indices]
is.match.name <- is.match[, dup.col.indices]#TODO drop=FALSE + test.
if(any(1 < rowSums(is.match.name))){
stop(domain=NA, gettextf("duplicate capture group names are only allowed in alternatives, problem: %s", dup.name))
}
Expand Down
16 changes: 15 additions & 1 deletion tests/testthat/test-CRAN-alternatives.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ test_that("altlist + alternatives with names ok", {
expect_identical(match.dt[["year"]], c("1983", "2017", "1984"))
})

test_that("alternatives_with_shared_groups ok", {
test_that("alternatives_with_shared_groups ok with 3 subjects", {
subject.vec <- c("mar 17, 1983", "26 sep 2017", "17 mar 1984")
pattern <- nc::alternatives_with_shared_groups(
month="[a-z]{3}", day="[0-9]{2}", year="[0-9]{4}",
Expand All @@ -158,3 +158,17 @@ test_that("alternatives_with_shared_groups ok", {
expect_identical(match.dt[["day"]], c("17", "26", "17"))
expect_identical(match.dt[["year"]], c("1983", "2017", "1984"))
})

test_that("alternatives_with_shared_groups ok with 1 subject", {
subject.vec <- "mar 17, 1983"
pattern <- nc::alternatives_with_shared_groups(
month="[a-z]{3}", day="[0-9]{2}", year="[0-9]{4}",
list(month, " ", day, ", ", year),
list(day, " ", month, " ", year))
match.dt <- nc::capture_first_vec(subject.vec, pattern)
sorted.names <- c("day", "month", "year")
expect_identical(sort(names(match.dt)), sorted.names)
expect_identical(match.dt[["month"]], "mar")
expect_identical(match.dt[["day"]], "17")
expect_identical(match.dt[["year"]], "1983")
})

0 comments on commit 3325b53

Please sign in to comment.