tests/testthat/test-11-xml.R

context("10-xml()")


# fail because of file -------------------------------------------------------------

test_that(
  "read_xml() fails when file does not exist",
  {
    expect_error(
      object = read_xml("DOES_NOT_EXIST"),
      regexp = "'DOES_NOT_EXIST' does not exist in current working directory"
    )
  }
)


test_that(
  "read_xml() fails when file does not have right extension",
  {
    expect_error(
      object = read_xml( scheme_path_xlsx() ),
      regexp = "Start tag expected"
    )
  }
)


# read from xml --- value -----------------------------------------------------------

test_that(
  "read_xml()",
  {
    expect_equal(
      object = read_xml(
        file = scheme_path_xml()
      ),
      expected = dmdScheme_example()
    )
  }
)

# Round trip --------------------------------------------------------------

test_that(
  "read_xml() --> write_xml() roundtrip",
  {
    expect_equal(
      object = dmdScheme_example() %>% write_xml(file = tempfile(fileext = ".xml")) %>% read_xml() %>% `attr<-`("fileName", "none"),
      expected = dmdScheme_example() %>% `attr<-`("fileName", "none")
    )
  }
)

Try the dmdScheme package in your browser

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

dmdScheme documentation built on Aug. 22, 2022, 9:06 a.m.