tests/testthat/test-has_xml_opening_tag.R

context("has_xml_opening_tag")

test_that("use on known tag", {

  text <- c(
    "  <a id=1>",
    "    some text",
    "  </a>"
  )

  testthat::expect_true(
    has_xml_opening_tag(text)
  )
  testthat::expect_true(
    has_xml_opening_tag(text, section = "a")
  )
  testthat::expect_false(
    has_xml_opening_tag(text, section = "nonsense")
  )
  testthat::expect_false(
    has_xml_opening_tag("", section = "nonsense")
  )

})



test_that("abuse", {

  text <- c(
    "<a>",
    "  some text",
    "</a>"
  )

  testthat::expect_error(
    has_xml_opening_tag(text, section = NULL),
    "'section' must be NA or a word"
  )

})
richelbilderbeek/beautier documentation built on Nov. 6, 2023, 10:20 a.m.