Skip to content

Commit

Permalink
better structure to maintain
Browse files Browse the repository at this point in the history
  • Loading branch information
wibeasley committed Jul 15, 2023
1 parent 0f207f1 commit a8a9ac2
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions tests/testthat/test-metadata-utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ library(testthat)
test_that("Named Captures", {
pattern_checkboxes <- "(?<=\\A| \\| )(?<id>\\d{1,}), (?<label>[\x20-\x7B\x7D-\x7E]{1,})(?= \\| |\\Z)"

ds_expected <-
tibble::tribble(
~id, ~label,
"1", "American Indian/Alaska Native",
"2", "Asian",
"3", "Native Hawaiian or Other Pacific Islander",
"4", "Black or African American",
"5", "White",
"6", "Unknown / Not Reported"
)

choices_1 <- "1, American Indian/Alaska Native | 2, Asian | 3, Native Hawaiian or Other Pacific Islander | 4, Black or African American | 5, White | 6, Unknown / Not Reported"
ds_boxes <- regex_named_captures(pattern=pattern_checkboxes, text=choices_1)

ds_expected <- structure(
list(
id = c("1", "2", "3", "4", "5", "6"),
label = c("American Indian/Alaska Native", "Asian", "Native Hawaiian or Other Pacific Islander", "Black or African American", "White", "Unknown / Not Reported")
),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA, -6L)
)

expect_equal(ds_boxes, expected=ds_expected, label="The returned data.frame should be correct") #dput(ds_boxes)
expect_s3_class(ds_boxes, "tbl")
})
Expand Down Expand Up @@ -48,7 +50,7 @@ test_that("checkbox choices -digits", {
})

test_that("checkbox choices -letters", {
ds_expected <-
ds_expected <- # datapasta::tribble_paste(ds_expected)
tibble::tribble(
~id, ~label,
"a", "American Indian/Alaska Native",
Expand Down Expand Up @@ -77,20 +79,21 @@ test_that("checkbox choices -letters", {


test_that("checkbox choices with special characters", {
choices_1 <- "1, Hospital A | 2, Hospitäl B | 3, Hospital Ç | 4, Hospítal D"

ds_boxes <- checkbox_choices(select_choices=choices_1)

ds_expected <- structure(
list(
id = c("1", "2", "3", "4"),
label = c("Hospital A", "Hospitäl B", "Hospital Ç", "Hospítal D")
),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA, -4L)
)
ds_expected <- # datapasta::tribble_paste(ds_expected)
tibble::tribble(
~id, ~label,
"1", "Hospital A",
"2", "Hospitäl B",
"3", "Hospital Ç",
"4", "Hospítal D"
)

expect_equal(ds_boxes, expected=ds_expected, label="The returned data.frame should be correct")
expect_s3_class(ds_boxes, "tbl")
"1, Hospital A | 2, Hospitäl B | 3, Hospital Ç | 4, Hospítal D" |>
checkbox_choices() |>
expect_equal(ds_expected)
})

###############################################################################
Expand All @@ -111,18 +114,17 @@ test_that("checkbox choices with special characters", {
# REDCap versions
###############################################################################
test_that("checkbox choices with errant space", {
choices_1 <- "1, Depressive mood disorder | 2, Adjustment disorder| 3, Personality disorder | 4, Anxiety | 0, Not Noted"
ds_boxes <- checkbox_choices(select_choices=choices_1)

ds_expected <- structure(
list(
id = c("1", "2", "3", "4", "0"),
label = c("Depressive mood disorder", "Adjustment disorder", "Personality disorder", "Anxiety", "Not Noted")
),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA, -5L)
)

expect_equal(ds_boxes, expected=ds_expected, label="The returned data.frame should be correct")
expect_s3_class(ds_boxes, "tbl")
ds_expected <-
tibble::tribble(
~id, ~label,
"1", "Depressive mood disorder",
"2", "Adjustment disorder",
"3", "Personality disorder",
"4", "Anxiety",
"0", "Not Noted"
)

"1, Depressive mood disorder | 2, Adjustment disorder| 3, Personality disorder | 4, Anxiety | 0, Not Noted" |>
checkbox_choices() |> # datapasta::tribble_paste()
expect_equal(ds_expected)
})

0 comments on commit a8a9ac2

Please sign in to comment.