File: test-xml_namespaces.R

package info (click to toggle)
r-cran-xml2 1.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 976 kB
  • sloc: cpp: 1,828; xml: 333; javascript: 238; ansic: 213; sh: 74; makefile: 6
file content (42 lines) | stat: -rw-r--r-- 1,437 bytes parent folder | download | duplicates (3)
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
37
38
39
40
41
42
# XML parsing tests ------------------------------------------------------------

test_that("multiple default namespaces given unique names", {
  ns <- unclass(xml_ns(read_xml(test_path("ns-multiple-default.xml"))))
  expect_equal(ns, c(d1 = "http://foo.com", d2 = "http://bar.com"))
})

test_that("repeated prefixes given unique names", {
  ns <- unclass(xml_ns(read_xml(test_path("ns-multiple-prefix.xml"))))
  expect_equal(ns, c(b = "http://baz.com", b1 = "http://bar.com"))
})

test_that("aliased prefixes retained", {
  ns <- unclass(xml_ns(read_xml(test_path("ns-multiple-aliases.xml"))))
  expect_equal(ns, c(b = "http://bar.com", c = "http://bar.com"))
})


# Low-level character vector tests ---------------------------------------------

test_that("unique prefix-url combo unchanged", {
  x <- c(blah = "http://blah.com", rah = "http://rah.com")
  expect_equal(.Call(unique_ns, x), x)
})

test_that("all prefixs kept", {
  x <- c(blah = "http://blah.com", rah = "http://blah.com")
  expect_named(.Call(unique_ns, x), c("blah", "rah"))
})

test_that("multiple default namespaces can be stripped", {
  x <- read_xml(test_path("ns-multiple-default.xml"))
  ns <- unclass(xml_ns(x))
  expect_equal(ns, c(d1 = "http://foo.com", d2 = "http://bar.com"))
  expect_length(xml_find_all(x, "//bar"), 0)

  xml_ns_strip(x)
  ns <- unclass(xml_ns(x))

  expect_equal(unname(ns), character())
  expect_length(xml_find_all(x, "//bar"), 2)
})