test_that("data_news works as expected for h1 & h2", { skip_if_no_pandoc() lines_h1 <- c( "# testpackage 1.0.0.9000", "", "* bullet (#222 @someone)", "", "# testpackage 1.0.0", "", "## sub-heading", "", "* first thing (#111 @githubuser)", "", "* second thing", "" ) lines_h2 <- gsub("^#", "##", lines_h1) pkg <- local_pkgdown_site() pkg <- pkg_add_file(pkg, "NEWS.md", lines_h1) expect_snapshot_output(data_news(pkg)[c("version", "page", "anchor")]) pkg <- pkg_add_file(pkg, "NEWS.md", lines_h2) expect_snapshot_output(data_news(pkg)[c("version", "page", "anchor")]) }) test_that("news is syntax highlighted once", { pkg <- local_pkgdown_site() pkg <- pkg_add_file(pkg, "NEWS.md", c( "# testpackage 1.0.0.9000", "```r", "x <- 1", "```" )) suppressMessages(build_news(pkg, preview = FALSE)) html <- xml2::read_html(path(pkg$dst_path, "news", "index.html")) expect_equal(xpath_text(html, "//code"), "x <- 1") }) test_that("multi-page news are rendered", { skip_if_no_pandoc() pkg <- local_pkgdown_site(meta = list(news = list(one_page = FALSE))) pkg <- pkg_add_file(pkg, "NEWS.md", c( "# testpackage 2.0", "", "* bullet (#222 @someone)", "", "# testpackage 1.1", "", "* bullet (#222 @someone)", "", "# testpackage 1.0.1", "", "* bullet (#222 @someone)", "", "# testpackage 1.0.0", "", "## sub-heading", "", "* first thing (#111 @githubuser)", "", "* second thing" )) expect_snapshot(data_news(pkg)[c("version", "page", "anchor")]) expect_snapshot(build_news(pkg)) # test that index links are correct lines <- xml2::read_html(path(pkg$dst_path, "news", "index.html")) expect_equal( xpath_attr(lines, "//main//a", "href"), c("news-2.0.html", "news-1.1.html", "news-1.0.html") ) expect_equal( xpath_text(lines, "//main//a"), c("Version 2.0", "Version 1.1", "Version 1.0") ) # test single page structure lines <- xml2::read_html(path(pkg$dst_path, "news", "news-1.0.html")) expect_equal(xpath_text(lines, ".//h1"), "Version 1.0") expect_equal(xpath_text(lines, ".//main//h2"), c("testpackage 1.0.0", "testpackage 1.0.1")) }) test_that("github links are added to news items", { skip_if_no_pandoc() pkg <- local_pkgdown_site(meta = list( repo = list( url = list( home = "https://github.com/r-lib/pkgdown", user = "https://github.com/", issue = "https://github.com/r-lib/pkgdown/issues/" ) ) )) pkg <- pkg_add_file(pkg, "NEWS.md", c( "# testpackage 0.1.0", "", "## Major changes", "", "- Bug fixes (@hadley, #100)", "", "- Merges (@josue-rodriguez)" )) news_tbl <- data_news(pkg) html <- xml2::read_xml(news_tbl$html) expect_equal( xpath_attr(html, ".//a", "href"), c( "https://github.com/hadley", "https://github.com/r-lib/pkgdown/issues/100", "https://github.com/josue-rodriguez" ) ) }) test_that("pkg_timeline fails cleanly for unknown package", { skip_on_cran() expect_null(pkg_timeline("__XYZ__")) }) test_that("pkg_timeline works for package that have been archived", { skip_on_cran() expect_no_error(pkg_timeline("PF")) }) test_that("correct timeline for first ggplot2 releases", { skip_on_cran() timeline <- pkg_timeline("ggplot2")[1:3, ] expected <- data.frame( version = c("0.5", "0.5.1", "0.5.2"), date = as.Date(c("2007-06-01", "2007-06-09", "2007-06-18")) ) expect_equal(timeline, expected) }) # news_title and version_page ----------------------------------------------- test_that("can recognise common forms of title", { # Variants in beginning version <- news_version(c( "foo 1.3.0", "foo v1.3.0", "foo 1.3.0", "VERSION 1.3.0", "changes in 1.3.0", "changes in foo version 1.3.0" ), "foo") expect_equal(version, rep("1.3.0", length(version))) # Variants in version spec expect_equal( news_version(c("foo 1-2", "foo 1-2-3", "foo 1-2-3-4"), "foo"), c("1-2", "1-2-3", "1-2-3-4") ) expect_equal( news_version("foo (development version)", "foo"), "development version" ) }) test_that("correctly collapses version to page for common cases", { versions <- c("1.0.0", "1.0.0.0", "1.0.0.9000", "development version") pages <- purrr::map_chr(versions, version_page) expect_equal(pages, c("1.0", "1.0", "dev", "dev")) }) # Tweaks ------------------------------------------------------------------ test_that("sections tweaked down a level", { html <- xml2::read_xml("