Skip to content

Commit

Permalink
Refactor to_singular and to_plural so that they return values, and te…
Browse files Browse the repository at this point in the history
…st those function during builds
  • Loading branch information
crew102 committed Aug 21, 2022
1 parent 37c7787 commit a1291b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
22 changes: 12 additions & 10 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,27 @@ validate_pv_data <- function(data) {

#' @noRd
to_singular <- function(plural) {
# assignees is an exception, singular isn't assigne

if (endsWith(plural, "ies")) {
singular <- sub("ies$", "y", plural)
} else if (endsWith(plural, "es") && !endsWith(plural, "ees")) {
singular <- sub("es$", "", plural)
if (endsWith(plural, "ees")) {
sub("ees$", "ee", plural)
} else if (endsWith(plural, "ies")) {
sub("ies$", "y", plural)
} else if (endsWith(plural, "es")) {
sub("es$", "", plural)
} else if (endsWith(plural, "s")) {
sub("s$", "", plural)
} else {
singular <- sub("s$", "", plural)
plural
}
}


#' @noRd
to_plural <- function(singular) {
if (endsWith(singular, "y")) {
plural <- sub("y$", "ies", singular)
sub("y$", "ies", singular)
} else if (endsWith(singular, "s")) {
plural <- paste0(singular, "es")
paste0(singular, "es")
} else {
plural <- paste0(singular, "s")
paste0(singular, "s")
}
}
13 changes: 2 additions & 11 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
context("validate_args")

eps <- (get_endpoints())
eps <- eps[eps != "locations"]
context("utils")

test_that("we can convert endpoints to their singular form and back", {
skip_on_cran()
skip_on_ci()

# the endpoints are plural so if we convert to singular and back they should be unchanged

eps <- get_endpoints()
z <- vapply(eps, function(x) {
# say what? only to_singular is used by the package. remove the others?
to_plural(to_singular(x))
}, FUN.VALUE = character(1), USE.NAMES = FALSE)

expect_equal(eps, z)
})

0 comments on commit a1291b3

Please sign in to comment.