From 73dc75729ac19985a6a8f4cf46d03a092d899308 Mon Sep 17 00:00:00 2001 From: Maximilian Held Date: Thu, 4 Mar 2021 20:17:03 +0100 Subject: [PATCH] enforce some length stability opens #183 --- R/import.R | 2 ++ tests/testthat/test-import.R | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/R/import.R b/R/import.R index 587a3f38..0dfbab53 100644 --- a/R/import.R +++ b/R/import.R @@ -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()]. diff --git a/tests/testthat/test-import.R b/tests/testthat/test-import.R index 051cb61b..39be3e14 100644 --- a/tests/testthat/test-import.R +++ b/tests/testthat/test-import.R @@ -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) })