File: test-xml_structure.R

package info (click to toggle)
r-cran-xml2 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 976 kB
  • sloc: cpp: 1,826; xml: 333; javascript: 238; ansic: 178; sh: 71; makefile: 6
file content (36 lines) | stat: -rw-r--r-- 900 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
test_that("xml_structure", {
  expect_output(
    xml_structure(read_xml("<a><b><c/><c/></b><d/></a>")),
    "<a>
  <b>
    <c>
    <c>
  <d>"
  )

  expect_output(
    xml_structure(read_xml("<a><b><c/><c/></b><d/></a>"), indent = 0L),
    "<a>
<b>
<c>
<c>
<d>"
  )
})

test_that("xml_structure can write to a file (#244)", {
  tmp <- tempfile()
  xml_structure(read_xml("<a><b><c/><c/></b><d/></a>"), file = tmp)
  expect_equal(readLines(tmp), c("<a>", "  <b>", "    <c>", "    <c>", "  <d>"))

  # repeated calls erase existing content
  xml_structure(read_xml("<a><b><c/><c/></b><d/></a>"), file = tmp)
  expect_equal(readLines(tmp), c("<a>", "  <b>", "    <c>", "    <c>", "  <d>"))
})

test_that("xml_structure is correct", {
  x <- read_html(test_path("lego.html.bz2"))

  quicklinks <- xml_find_first(x, "//div[contains(@div, 'quicklinks')]")
  expect_snapshot(html_structure(quicklinks))
})