Skip to content

Commit

Permalink
enforce some length stability opens #183
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Mar 4, 2021
1 parent d0bf62c commit 73dc757
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions R/import.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ get_cr_md <- function(dois,
out
}

# wrapped cr api calls ====

#' Get Crossref Works
#'
#' Type-/length-stable, defensive and cached variant of [rcrossref::cr_works()].
Expand Down
26 changes: 21 additions & 5 deletions tests/testthat/test-import.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
test_that("Crossref metadata can be read in", {
dois <- tu_dois()[2:5]
res <- cr_works2(dois)
expect_equal(nrow(res), length(dois))
# wrapped cr api calls ====

dois <- tu_dois()[2:5]

test_that("Crossref metadata can be read in", {
# testthat does not seem to know about vctrs equality
# https://github.com/r-lib/testthat/issues/1349
expect_true(all(biblids::as_doi(res$doi) == biblids::as_doi(dois)))
expect_true(
all(biblids::as_doi(cr_works2(dois)$doi) == biblids::as_doi(dois))
)
})

test_that("cr_works2 is length-stable", {
expect_equal(nrow(cr_works2(dois)), length(dois))
expect_equal(nrow(cr_works2(dois[1])), 1)
skip("Length instability in columns cannot be repaired by wrapper.")
# blocked by https://github.com/subugoe/metacheck/issues/183
expect_equal(ncol(cr_works2(dois)), ncol(cr_works2(dois[1])))
})

test_that("Bad DOIs throw error", {
skip("Not implemented")
expect_equal(1, 1)
})

0 comments on commit 73dc757

Please sign in to comment.