Skip to content

Commit

Permalink
Merge f488f9e into 660737b
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolepore committed Jan 5, 2019
2 parents 660737b + f488f9e commit 20d190b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 48 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ importFrom(glue,glue)
importFrom(magrittr,"%>%")
importFrom(rlang,"%||%")
importFrom(rlang,.data)
importFrom(rlang,abort)
importFrom(rlang,enquos)
importFrom(rlang,inform)
importFrom(rlang,set_names)
importFrom(rlang,warn)
2 changes: 1 addition & 1 deletion R/imports.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @importFrom rlang .data %||% enquos set_names
#' @importFrom rlang .data %||% enquos set_names inform warn abort
#' @importFrom dplyr filter select mutate group_by ungroup arrange
#' @importFrom glue glue
NULL
Expand Down
16 changes: 14 additions & 2 deletions R/reference_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ reference_package <- function(x,
url = NULL,
packages = NULL,
strip_s3class = TRUE) {
pick_docs("package")(x, url = url, packages = packages) %>%
out <- pick_docs("package")(x, url = url, packages = packages) %>%
tidy_reference(strip_s3class)

if (identical(nrow(out), 0L)) {
warn(glue("No package matches '{x}'."))
}

out
}

#' @rdname reference_package
Expand All @@ -59,8 +65,14 @@ reference_concept <- function(x,
url = NULL,
packages = NULL,
strip_s3class = TRUE) {
pick_docs("concept")(x, url = url, packages = packages) %>%
out <- pick_docs("concept")(x, url = url, packages = packages) %>%
tidy_reference(strip_s3class)

if (identical(nrow(out), 0L)) {
warn(glue("No concept matches '{x}'."))
}

out
}

tidy_reference <- function(.data, strip_s3class) {
Expand Down
76 changes: 35 additions & 41 deletions tests/testthat/test-reference_package.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
context("reference_package")

test_that("with fgeo outputs the expected data structure", {
skip_if_not_installed("fgeo")

result <- reference_package("fgeo")
expect_is(result, "data.frame")
expect_named(result, c("topic", "alias", "title"))
context("reference_concept")

# Compare next test
expect_false(grepl("href", result$topic[[1]]))
test_that("reference_concept fails gracefully w/ inexisting concept", {
expect_warning(
reference_concept("bad concept"),
"No concept matches.*bad concept"
)
})

test_that("reference_concept picks one topic & is sensitive to `packages`", {
expect_equal(
reference_concept("combine strings", packages = "base")$topic,
"paste"
)
})
test_that("with fgeo is sensitive adds a url", {
skip_if_not_installed("fgeo")

test_that("reference_package adds a url", {
skip_if_not_installed("base")

expect_true(
grepl("href", reference_package("fgeo", url = "https://...")$topic[[1]])
grepl("href", reference_package("base", url = "https://...")$topic[[1]])
)
})

test_that("works with base", {
expect_is(reference_package("base"), "data.frame")


context("reference_package")

test_that("reference_package fails gracefully w/ inexisting concept", {
expect_warning(
reference_package("badpackage"),
"No package matches.*badpackage"
)
})

test_that("is sensitive to strip_s3class", {
Expand All @@ -41,37 +54,18 @@ test_that("is sensitive to strip_s3class", {
expect_false("all.equal.character" %in% strip_true)
})

test_that("picks expected topic and is sensitive to `packages`", {
expect_equal(
reference_concept("combine strings", packages = "base")$topic,
"paste"
)
expect_equal(
reference_concept("combine strings", packages = "not_a_package")$alias,
character(0)
)
})

test_that("no longer includes package documentation", {
test_that("reference_package with fgeo outputs the expected data structure", {
skip_if_not_installed("fgeo")
expect_false(any(grepl("fgeo-package", unique(reference_package("fgeo")$alias))))
})

test_that("no longer misses fgeo_elevation", {
skip_if_not_installed("fgeo.tool")
expect_true(any(grepl("fgeo_elevation", reference_package("fgeo.tool")$alias)))
result <- reference_package("fgeo")
expect_is(result, "data.frame")
expect_named(result, c("topic", "alias", "title"))

# Compare next test
expect_false(grepl("href", result$topic[[1]]))
})

test_that("no longer picks demography_impl", {
skip_if_not_installed("fgeo.analyze")
test_that("reference_package no longer includes package documentation", {
skip_if_not_installed("fgeo")

strip_false <- reference_concept(
"demography functions",
url = NULL,
packages = fgeo:::fgeo_packages()
)$topic

expect_false(any(grepl("demography_impl", strip_false)))
expect_true(any(grepl("demography_ctfs", strip_false)))
expect_false(any(grepl("fgeo-package", unique(reference_package("fgeo")$alias))))
})
5 changes: 1 addition & 4 deletions tests/testthat/test-s3_strip_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ test_that("does nothing with non existing functions", {
})

test_that("outputs expected generics", {
skip_if_not_installed("fgeo.analyze")
library(fgeo.analyze)

expect_equal(
s3_strip_class(c(
"print.data.frame",
"to_df.tt_lst",
"print"
)),
c("print", "to_df", "print")
c("print", "print")
)
})

0 comments on commit 20d190b

Please sign in to comment.