Skip to content

Commit

Permalink
add tests for split_by as numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
lcougnaud committed Jan 2, 2025
1 parent b5a8750 commit b7d3781
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/testthat/test-gitbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,56 @@ test_that("gitbook() correctly handles extra_dependency after its own", {
extra_css <- xml2::xml_find_all(gitbook_css, "./following-sibling::link[contains(@href, 'font-awesome')]")
expect_gt(length(extra_css), 0L)
})

test_that("gitbook() correctly splits with a specified numeric", {

skip_on_cran()
skip_if_not_pandoc()
skip_if_not_installed("xml2")

rmd <- local_rmd_file(
c("---", "title: test split_by as numeric", "---", "",
"# CHAPTER 1", "## SECTION 1", "### SUBSECTION 1",
"#### SUBSUBSECTION 1",
"", "# CHAPTER 2", "## SECTION 2")
)
res <- local_render_book(rmd, output_format = gitbook(split_by = "4", toc_depth = 4))
content <- xml2::read_html(res)

TOC <- xml2::xml_find_all(content, "//div[@class='book-summary']/nav/ul//li")

expect_equal(
xml2::xml_attr(TOC, "data-level"),
c("1", "1.1", "1.1.1", "1.1.1.1", "2", "2.1")
)
expect_equal(
xml2::xml_attr(TOC, "data-path"),
c("chapter-1.html", "section-1.html", "subsection-1.html",
"subsubsection-1.html", "chapter-2.html", "section-2.html")
)

})

test_that("gitbook() split by section is equivalent of split by 2", {

skip_on_cran()
skip_if_not_pandoc()
skip_if_not_installed("xml2")

rmd <- local_rmd_file(
c("---", "title: test split_by section", "---", "",
"# CHAPTER 1", "## SECTION 1", "### SUBSECTION 1",
"# CHAPTER 2", "## SECTION 2")
)

resSection <- local_render_book(rmd,
output_format = gitbook(split_by = "section"))
contentSection <- xml2::read_html(resSection)

res2 <- local_render_book(rmd,
output_format = gitbook(split_by = "2"))
content2 <- xml2::read_html(res2)

expect_equal(object = content2, expected = contentSection)

})

0 comments on commit b7d3781

Please sign in to comment.