Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests following Pandoc change in 2.18 #2334

Merged
merged 8 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@ jobs:
matrix:
config:
# testing R release with last shipped pandoc version in RStudio IDE and new pandoc
- {os: windows-latest, pandoc: '2.16.2', r: 'release'}
- {os: macOS-latest, pandoc: '2.16.2', r: 'release'}
- {os: ubuntu-18.04, pandoc: '2.16.2', r: 'release'}
- {os: windows-latest, pandoc: '2.18', r: 'release'}
- {os: macOS-latest, pandoc: '2.18', r: 'release'}
- {os: ubuntu-18.04, pandoc: '2.18', r: 'release'}
- {os: ubuntu-18.04, pandoc: 'devel', r: 'release'}
# testing older pandoc versions
- {os: ubuntu-18.04, pandoc: '2.17.1.1', r: 'release'}
- {os: ubuntu-18.04, pandoc: '2.14.2', r: 'release'}
- {os: ubuntu-18.04, pandoc: '2.11.4', r: 'release'}
- {os: ubuntu-18.04, pandoc: '2.7.3', r: 'release'}
- {os: ubuntu-18.04, pandoc: '2.5', r: 'release'}
- {os: ubuntu-18.04, pandoc: '2.0.0.1', r: 'release'}
# testing other R versions
- {os: ubuntu-18.04, pandoc: '2.11.4', r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-18.04, pandoc: '2.11.4', r: 'oldrel-1'}
- {os: ubuntu-18.04, pandoc: '2.11.4', r: 'oldrel-2'}
- {os: ubuntu-18.04, pandoc: '2.11.4', r: 'oldrel-3'}
- {os: ubuntu-18.04, pandoc: '2.11.4', r: 'oldrel-4'}
- {os: ubuntu-18.04, pandoc: '2.14.2', r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-18.04, pandoc: '2.14.2', r: 'oldrel-1'}
- {os: ubuntu-18.04, pandoc: '2.14.2', r: 'oldrel-2'}
- {os: ubuntu-18.04, pandoc: '2.14.2', r: 'oldrel-3'}
- {os: ubuntu-18.04, pandoc: '2.14.2', r: 'oldrel-4'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

- <a href="#1-section" id="toc-1-section">1 Section</a>
- <a href="#2-header" id="toc-2-header">2 Header</a>

# 1 Section

Sentence.

# 2 Header

Sentence
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

- <a href="#10-section" id="toc-10-section">10 Section</a>
- <a href="#header" id="toc-header">Header</a>

# 10 Section

Sentence.

# Header

Sentence
44 changes: 44 additions & 0 deletions tests/testthat/_snaps/after-pandoc-2.18/lua-filters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# number_sections Lua filter works

# 1 A

## 1.1 B

# 2 C

## 2.1 D

See [A](#a)

---

# 1 A

## 1.1 B

# 2 C

## 2.1 D

See [A](#1-a)

---

Test
================

- <a href="#1-a" id="toc-1-a">1 A</a>
- <a href="#11-b" id="toc-11-b">1.1 B</a>
- <a href="#2-c" id="toc-2-c">2 C</a>
- <a href="#21-d" id="toc-21-d">2.1 D</a>

# 1 A

## 1.1 B

# 2 C

## 2.1 D

See [A](#1-a)

Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,23 @@

See [A](#1-a)

---

Test
================

- [1 A](#1-a)
- [1.1 B](#11-b)
- [2 C](#2-c)
- [2.1 D](#21-d)

# 1 A

## 1.1 B

# 2 C

## 2.1 D

See [A](#1-a)

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

- [1 Section](#1-section)
- [2 Header](#2-header)

# 1 Section

Sentence.

# 2 Header

Sentence
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

- [10 Section](#10-section)
- [Header](#header)

# 10 Section

Sentence.

# Header

Sentence
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/github_document/github-toc-numbered.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

- [1 Section](#1-section)
- [2 Header](#2-header)
- <a href="#1-section" id="toc-1-section">1 Section</a>
- <a href="#2-header" id="toc-2-header">2 Header</a>

# 1 Section

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/github_document/github-toc.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

- [10 Section](#10-section)
- [Header](#header)
- <a href="#10-section" id="toc-10-section">10 Section</a>
- <a href="#header" id="toc-header">Header</a>

# 10 Section

Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-github_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ test_that("toc has correct identifier", {
tmp_file <- local_rmd_file(
c("# 10 Section","","Sentence.","", "# Header","","Sentence ")
)
pandoc_version <- ifelse(pandoc_available("2.18"), "after-pandoc-2.18", "before-pandoc-2.18")
res <- render(tmp_file, github_document(toc = TRUE, html_preview = FALSE))
expect_snapshot_file(res, "github-toc.md", compare = compare_file_text)
expect_snapshot_file(res, "github-toc.md", compare = compare_file_text, variant = pandoc_version)
})

test_that("toc has correct identifier also when sections are numbered ", {
Expand All @@ -17,8 +18,9 @@ test_that("toc has correct identifier also when sections are numbered ", {
tmp_file <- local_rmd_file(
c("# Section","","Sentence.","", "# Header","","Sentence ")
)
pandoc_version <- ifelse(pandoc_available("2.18"), "after-pandoc-2.18", "before-pandoc-2.18")
res <- render(tmp_file, github_document(toc = TRUE, number_sections = TRUE, html_preview = FALSE))
expect_snapshot_file(res, "github-toc-numbered.md", compare = compare_file_text)
expect_snapshot_file(res, "github-toc-numbered.md", compare = compare_file_text, variant = pandoc_version)
})


Expand Down
14 changes: 10 additions & 4 deletions tests/testthat/test-lua-filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,29 @@ test_that("number_sections Lua filter works", {
headers <- c("# A", "## B", "# C", "## D")
rmd <- c(paste0(headers, "\n\n"), "See [A]")
# Variant for snapshot: pandoc 2.11.2 default to atx headers
pandoc_2.11.2 <- ifelse(pandoc_available("2.11.2"), "pandoc-2.11.2", "pandoc-before-2.11.2")
pandoc_versions <- if (pandoc_available("2.18")) {
"after-pandoc-2.18"
} else if (pandoc_available("2.11.2")) {
"after-pandoc-2.11.2"
} else {
"before-pandoc-2.11.2"
}
# -gfm_auto_identifiers
result <- .generate_md_and_convert(rmd, md_document(number_sections = TRUE))
expect_snapshot_output(result, variant = pandoc_2.11.2)
expect_snapshot_output(result, variant = pandoc_versions)

# +gfm_auto_identifiers
skip_if_not_pandoc("2.5") # gfm_auto_identifiers is not working the same before
result <- .generate_md_and_convert(
rmd,
md_document(number_sections = TRUE, md_extensions = "+gfm_auto_identifiers")
)
expect_snapshot_output(result, variant = pandoc_2.11.2)
expect_snapshot_output(result, variant = pandoc_versions)

# Github document
skip_if_not_pandoc("2.10.1") # changes in gfm writer break this test for earlier versions
result <- .generate_md_and_convert(rmd, github_document(number_sections = TRUE, toc = TRUE))
expect_snapshot_output(result, variant = pandoc_2.11.2)
expect_snapshot_output(result, variant = pandoc_versions)
})

test_that("latex-divs.lua works with HTML doc", {
Expand Down