diff --git a/tests/testthat/test-gitbook.R b/tests/testthat/test-gitbook.R index abf1345dd..5e62f92bb 100644 --- a/tests/testthat/test-gitbook.R +++ b/tests/testthat/test-gitbook.R @@ -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) + +})