From 713f72e3b21ffa7c91f7faad5afb4e9d9a0b65d9 Mon Sep 17 00:00:00 2001 From: Thierry Onkelinx Date: Sun, 29 Sep 2024 18:01:35 +0200 Subject: [PATCH] add unit tests --- R/qr_vcard.R | 4 +++- tests/testthat/test_e_qr_vcard.R | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/test_e_qr_vcard.R diff --git a/R/qr_vcard.R b/R/qr_vcard.R index 8a6cedf..b83a49c 100644 --- a/R/qr_vcard.R +++ b/R/qr_vcard.R @@ -63,7 +63,9 @@ qr_vcard <- function( ) |> vapply(vcard_wrap, character(1), width = 75) |> paste(collapse = "\r\n") |> - qr_code(ecl = ecl) + qr_code(ecl = ecl) -> output + class(output) <- c("qr_vcard", class(output)) + return(output) } #' @importFrom assertthat assert_that is.count is.string noNA diff --git a/tests/testthat/test_e_qr_vcard.R b/tests/testthat/test_e_qr_vcard.R new file mode 100644 index 0000000..641e78d --- /dev/null +++ b/tests/testthat/test_e_qr_vcard.R @@ -0,0 +1,39 @@ +test_that("qr_vcard()", { + expect_s3_class(qr_vcard(given = "Jane", family = "Doe"), "qr_vcard") + expect_s3_class( + qr_vcard( + given = "Jane", family = "Doe", middle = "J.", prefix = "Dr.", + suffix = "PhD", email = "jane@doe.com", tel = "+1234567890", + url = "https://jane.doe.com", organisation = "Doe Inc.", + job_title = "CEO", gender = "F", logo = "https://jane.doe.com/logo.png", + photo = "https://jane.doe.com/jane.jpg", + address = c( + street_nr = "123 Main St.", city = "Anytown", region = "NY", + postal_code = "12345", country = "USA" + ) + ), + "qr_vcard" + ) + expect_s3_class( + qr_vcard( + given = "Jane", family = "Doe", middle = c("J.", "J."), + prefix = c("Dr.", "ir."), suffix = c("PhD", "MSc"), + email = c(work = "jane@doe.com", "jane@hotmail.com"), tel = "+1234567890", + url = "https://jane.doe.com", organisation = "Doe Inc.", + job_title = "CEO", gender = "F", logo = "https://jane.doe.com/logo.png", + address = list( + work = c( + street_nr = "123 Main St.", city = "Anytown", region = "NY", + postal_code = "12345", country = "USA", pobox = "PO Box 123" + ), + home = c( + street_nr = "321 Main St.", city = "Anytown", region = "NY", + postal_code = "12345", country = "USA" + ) + ), + photo = +"https://jane.doe.com/public/employees/photos/curriculum_vitae/jane_doe.jpg" + ), + "qr_vcard" + ) +})