Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Oct 31, 2023
1 parent 594df9e commit 7f5e724
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/testthat/_snaps/xml_nodeset.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,22 @@
[9] <div id="more_if_no_javascript"><a href="/search/">More</a></div>
[10] <div class="magnifyingglass navbarSprite"></div>

---

Code
print(x, width = 13L)
Output
{xml_document}
<doc>
[1] <a>123 ...
[2] <b>123 ...
[3] <c>12\ ...
Code
print(x, width = 14L)
Output
{xml_document}
<doc>
[1] <a>1234 ...
[2] <b>1234 ...
[3] <c>12\\ ...

16 changes: 16 additions & 0 deletions tests/testthat/test-xml_nodeset.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,24 @@ test_that("methods work on empty nodesets", {
})

test_that("print method is correct", {
skip_if(getOption("width") < 20L, "Screen too narrow")

x <- read_html(test_path("lego.html.bz2"))
body <- xml_find_first(x, "//body")
divs <- xml_find_all(body, ".//div")[1:10]
expect_snapshot(print(divs))

# double-substring() logic
s <- c(
"123456789\\", # always too wide, '\' never encoded
"12345", # always fits
"12\\45" # doesn't fit when '\' is encoded
)
# embed as text on nodes <a>,<b>,<c>
s <- sprintf("<%1$s>%2$s</%1$s>", letters[1:3], s)
x <- read_xml(sprintf("<doc>%s</doc>", paste(s, collapse="")))
expect_snapshot({
print(x, width = 13L)
print(x, width = 14L)
})
})

0 comments on commit 7f5e724

Please sign in to comment.