From 0f207f146d7918a6707ed1bdb57fae12f5a50a2e Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Fri, 14 Jul 2023 19:26:03 -0500 Subject: [PATCH] test multiple scenarios with one expected dataset ref #500 cc: @BlairCooper --- tests/testthat/test-metadata-utilities.R | 65 +++++++++++++++++++----- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/tests/testthat/test-metadata-utilities.R b/tests/testthat/test-metadata-utilities.R index 7831bdce..c758ebce 100644 --- a/tests/testthat/test-metadata-utilities.R +++ b/tests/testthat/test-metadata-utilities.R @@ -19,21 +19,60 @@ test_that("Named Captures", { expect_s3_class(ds_boxes, "tbl") }) -test_that("checkbox choices", { - 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 <- checkbox_choices(select_choices=choices_1) +test_that("checkbox choices -digits", { + 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", + "66", "Unknown / Not Reported" + ) - 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) - ) + # well-behaved + "1, American Indian/Alaska Native | -2, Asian | 3, Native Hawaiian or Other Pacific Islander | 4, Black or African American | 5, White | 66, Unknown / Not Reported" |> + checkbox_choices() |> + expect_equal(ds_expected, label = "well-behaved:") - expect_equal(ds_boxes, expected=ds_expected, label="The returned data.frame should be correct") #dput(ds_boxes) - expect_s3_class(ds_boxes, "tbl") + # no leading spaces + "1, American Indian/Alaska Native |-2, Asian |3, Native Hawaiian or Other Pacific Islander |4, Black or African American |5, White |66, Unknown / Not Reported" |> + checkbox_choices() |> + expect_equal(ds_expected, label = "no leading spaces:") + + # no trailing spaces + "1, American Indian/Alaska Native| -2, Asian| 3, Native Hawaiian or Other Pacific Islander| 4, Black or African American| 5, White| 66, Unknown / Not Reported" |> + checkbox_choices() |> + expect_equal(ds_expected, label = "no trailing spaces:") +}) + +test_that("checkbox choices -letters", { + ds_expected <- + tibble::tribble( + ~id, ~label, + "a", "American Indian/Alaska Native", + "b", "Asian", + "c", "Native Hawaiian or Other Pacific Islander", + "dd", "Black or African American", + "eee", "White", + "f", "Unknown / Not Reported" + ) + + # well-behaved + "a, American Indian/Alaska Native | b, Asian | c, Native Hawaiian or Other Pacific Islander | dd, Black or African American | eee, White | f, Unknown / Not Reported" |> + checkbox_choices() |> + expect_equal(ds_expected, label = "well-behaved:") + + # no leading spaces + "a, American Indian/Alaska Native |b, Asian |c, Native Hawaiian or Other Pacific Islander |dd, Black or African American |eee, White |f, Unknown / Not Reported" |> + checkbox_choices() |> + expect_equal(ds_expected, label = "no leading spaces:") + + # no trailing spaces + "a, American Indian/Alaska Native| b, Asian| c, Native Hawaiian or Other Pacific Islander| dd, Black or African American| eee, White| f, Unknown / Not Reported" |> + checkbox_choices() |> + expect_equal(ds_expected, label = "no trailing spaces:") })