test_that("authors page includes inst/AUTHORS", { pkg <- local_pkgdown_site() pkg <- pkg_add_file(pkg, "inst/AUTHORS", "Hello") suppressMessages(build_citation_authors(pkg)) lines <- read_lines(path(pkg$dst_path, "authors.html")) expect_match(lines, "
Hello", all = FALSE) }) test_that("authors page includes multiline inst/AUTHORS", { pkg <- local_pkgdown_site() pkg <- pkg_add_file(pkg, "inst/AUTHORS", c("Hello", "------", "bla bla")) suppressMessages(build_citation_authors(pkg)) lines <- read_lines(path(pkg$dst_path, "authors.html")) content <- paste(lines, collapse = " ") expect_match(content, "
Hello ------ bla bla") }) test_that("data_authors validates yaml inputs", { data_authors_ <- function(...) { pkg <- local_pkgdown_site(meta = list(...)) data_authors(pkg) } expect_snapshot(error = TRUE, { data_authors_(authors = 1) data_authors_(authors = list(before = 1)) data_authors_(authors = list(after = 1)) }) }) test_that("data_home_sidebar_authors validates yaml inputs", { data_home_sidebar_authors_ <- function(...) { pkg <- local_pkgdown_site(meta = list(...)) data_home_sidebar_authors(pkg) } expect_snapshot(error = TRUE, { data_home_sidebar_authors_(authors = list(sidebar = list(roles = 1))) data_home_sidebar_authors_(authors = list(sidebar = list(before = 1))) data_home_sidebar_authors_( authors = list(sidebar = list(before = "x\n\ny")) ) }) }) # authors -------------------------------------------------------------------- test_that("ORCID can be identified & removed from all comment styles", { desc <- desc::desc( text = c( 'Authors@R: c(', ' person("no comment"),', ' person("bare comment", comment = "comment"),', ' person("orcid only", comment = c(ORCID = "1")),', ' person("both", comment = c("comment", ORCID = "2"))', ' )' ) ) authors <- purrr::map(desc$get_authors(), author_list, list()) expect_equal( purrr::map(authors, "orcid"), list(NULL, NULL, orcid_link("1"), orcid_link("2")) ) expect_equal( purrr::map(authors, "comment"), list(character(), "comment", character(), "comment") ) }) test_that("ROR can be identified & removed from all comment styles", { desc <- desc::desc( text = c( 'Authors@R: c(', ' person("no comment"),', ' person("bare comment", comment = "comment"),', ' person("ror only", comment = c(ROR = "1")),', ' person("both", comment = c("comment", ROR = "2"))', ' )' ) ) authors <- purrr::map(desc$get_authors(), author_list, list()) expect_equal( purrr::map(authors, "ror"), list(NULL, NULL, ror_link("1"), ror_link("2")) ) expect_equal( purrr::map(authors, "comment"), list(character(), "comment", character(), "comment") ) }) test_that("author comments linkified with escaped angle brackets (#2127)", { p <- list(name = "Jane Doe", roles = "rev", comment = "
inst/CITATION
",
all = FALSE,
fixed = TRUE
)
})
test_that("multiple citations all have HTML and BibTeX formats", {
pkg <- local_pkgdown_site()
pkg <- pkg_add_file(
pkg,
"inst/CITATION",
c(
'bibentry("misc", title="Proof of b < a > c", author=c("A", "B"), year="2021",
textVersion="A & B (2021): Proof of b < a > c.")',
'bibentry("misc", title="Title Two", author="Author Two", year="2022")'
)
)
citations <- data_citations(pkg$src_path)
expect_snapshot_output(citations)
})
test_that("bibtex is escaped", {
pkg <- local_pkgdown_site()
pkg <- pkg_add_file(
pkg,
"inst/CITATION",
c(
'citEntry(',
' entry = "Article",',
' title="test special HTML characters: <&>",',
' author="x",',
' journal="x",',
' year="2017",',
' textVersion = ""',
')'
)
)
suppressMessages(build_citation_authors(pkg))
html <- xml2::read_html(path(pkg$dst_path, "authors.html"))
expect_match(xpath_text(html, "//pre"), "<&>", fixed = TRUE)
})