tests/testthat/test-XML.R

test_that("XML with default `tabSize`", {
  skip_if(Sys.which("xmllint") == "", message = "'xmllint' not found")
  code <- c(
    "<item>",
    "<link>https://google.com</link>",
    "  </item>"
  )
  prettyCode <- prettifyXML(code)
  expect_equal(
    prettyCode,
    "<?xml version=\"1.0\"?>\n<item>\n  <link>https://google.com</link>\n</item>"
  )
})

test_that("XML with given `tabSize`", {
  skip_if(Sys.which("xmllint") == "", message = "'xmllint' not found")
  code <- c(
    "<item>",
    "<link>https://google.com</link>",
    "  </item>"
  )
  prettyCode <- prettifyXML(code, tabSize = 4)
  expect_equal(
    prettyCode,
    "<?xml version=\"1.0\"?>\n<item>\n    <link>https://google.com</link>\n</item>"
  )
})

test_that("XML from a file", {
  skip_if(Sys.which("xmllint") == "", message = "'xmllint' not found")
  code <- c(
    "<item>",
    "<link>https://google.com</link>",
    "  </item>"
  )
  tmpFile <- tempfile(fileext = ".xml")
  writeLines(code, tmpFile)
  prettyCode <- prettifyXML(tmpFile)
  expect_equal(
    prettyCode,
    "<?xml version=\"1.0\"?>\n<item>\n  <link>https://google.com</link>\n</item>"
  )
})

Try the prettifyAddins package in your browser

Any scripts or data that you put into this service are public.

prettifyAddins documentation built on Sept. 14, 2023, 5:06 p.m.