test_that("read_xml", {
xml <- 'A & B'
# TODO add test for isfile
# and do some actual tests
expect_silent(z <- readXMLPtr(xml, isfile = FALSE, escapes = FALSE, declaration = FALSE, whitespace = TRUE, empty_tags = FALSE, skip_control = TRUE))
expect_silent(z <- readXMLPtr(xml, isfile = FALSE, escapes = FALSE, declaration = TRUE, whitespace = TRUE, empty_tags = FALSE, skip_control = TRUE))
expect_silent(z <- readXMLPtr(xml, isfile = FALSE, escapes = TRUE, declaration = FALSE, whitespace = TRUE, empty_tags = FALSE, skip_control = TRUE))
expect_silent(z <- readXMLPtr(xml, isfile = FALSE, escapes = TRUE, declaration = TRUE, whitespace = TRUE, empty_tags = FALSE, skip_control = TRUE))
exp <- "A & B"
expect_equal(exp, readXML(xml, isfile = FALSE, escapes = FALSE, declaration = FALSE, whitespace = TRUE, empty_tags = FALSE, skip_control = TRUE))
exp <- "A & B"
expect_equal(exp, readXML(xml, isfile = FALSE, escapes = FALSE, declaration = TRUE, whitespace = TRUE, empty_tags = FALSE, skip_control = TRUE))
exp <- "A & B"
expect_equal(exp, readXML(xml, isfile = FALSE, escapes = TRUE, declaration = FALSE, whitespace = TRUE, empty_tags = FALSE, skip_control = TRUE))
exp <- "A & B"
expect_equal(exp, readXML(xml, isfile = FALSE, escapes = TRUE, declaration = TRUE, whitespace = TRUE, empty_tags = FALSE, skip_control = TRUE))
xml <- ""
expect_error(readXMLPtr(xml, isfile = FALSE, escapes = FALSE, declaration = FALSE, whitespace = TRUE, empty_tags = FALSE, skip_control = TRUE))
expect_error(readXML(xml, isfile = FALSE, escapes = FALSE, declaration = FALSE, whitespace = TRUE, empty_tags = FALSE, skip_control = TRUE))
})
test_that("xml_node", {
xml_str <- ""
xml <- read_xml(xml_str)
exp <- xml_str
expect_equal("a", getXMLXPtrName1(xml))
expect_equal(exp, getXMLXPtr0(xml))
expect_equal(exp, getXMLXPtr1(xml, "a"))
exp <- ""
expect_equal(exp, getXMLXPtr2(xml, "a", "b"))
exp <- ""
expect_equal(exp, getXMLXPtr3(xml, "a", "b", "c"))
# bit cheating, this test returns the same, but not the actual feature of "*"
expect_equal(exp, unkgetXMLXPtr3(xml, "a", "c"))
})
test_that("xml_value", {
exp <- "1"
xml_str <- "1"
xml <- read_xml(xml_str)
expect_equal(exp, getXMLXPtr1val(xml, "a"))
xml_str <- "1"
xml <- read_xml(xml_str)
expect_equal(exp, getXMLXPtr2val(xml, "a", "b"))
xml_str <- "1"
xml <- read_xml(xml_str)
expect_equal(exp, getXMLXPtr3val(xml, "a", "b", "c"))
})
test_that("xml_attr", {
exp <- list(c(a = "1"))
xml_str <- ""
xml <- read_xml(xml_str)
expect_equal(getXMLXPtr1attr(xml, "a"), exp)
xml_str <- ""
xml <- read_xml(xml_str)
expect_equal(getXMLXPtr2attr(xml, "b", "a"), exp)
xml_str <- ""
xml <- read_xml(xml_str)
expect_equal(getXMLXPtr3attr(xml, "c", "b", "a"), exp)
})
test_that("xml_append_child", {
xml_node <- read_xml("")
xml_child <- read_xml("&")
exp <- "&"
expect_equal(xml_append_child1(xml_node, xml_child, pointer = FALSE), exp)
# xml_node sets the flags for both
xml_node <- read_xml("", escapes = TRUE)
xml_child <- read_xml("&")
exp <- "&"
expect_equal(xml_append_child1(xml_node, xml_child, pointer = FALSE), exp)
xml_node <- ""
xml_child <- read_xml("")
xml_node <- xml_append_child1(read_xml(xml_node), xml_child, pointer = FALSE)
expect_equal(xml_node, "")
xml_node <- xml_append_child2(read_xml(xml_node), xml_child, level1 = "b", pointer = FALSE)
expect_equal(xml_node, "")
xml_node <- xml_append_child3(read_xml(xml_node), read_xml(""), level1 = "b", level2 = "c", pointer = FALSE)
expect_equal(xml_node, "")
# check that escapes does not throw a warning
xml_node <- ""
xml_child <- read_xml("a&b", escapes = FALSE)
xml_node <- xml_append_child1(read_xml(xml_node, escapes = TRUE), xml_child, pointer = FALSE)
expect_equal(xml_node, "a&b")
xml_node <- xml_append_child2(read_xml(xml_node, escapes = TRUE), xml_child, level1 = "b", pointer = FALSE)
expect_equal(xml_node, "a&ba&b")
xml_node <- xml_append_child3(read_xml(xml_node, escapes = TRUE), read_xml(""), level1 = "b", level2 = "c", pointer = FALSE)
expect_equal(xml_node, "a&ba&b")
# check that pointer is valid
expect_true(inherits(xml_append_child1(read_xml(xml_node), xml_child, pointer = TRUE), "pugi_xml"))
expect_true(inherits(xml_append_child1(read_xml(xml_node), xml_child, pointer = TRUE), "pugi_xml"))
expect_true(inherits(xml_append_child2(read_xml(xml_node), xml_child, level1 = "a", pointer = TRUE), "pugi_xml"))
expect_true(inherits(xml_append_child2(read_xml(xml_node), xml_child, level1 = "a", pointer = TRUE), "pugi_xml"))
expect_true(inherits(xml_append_child3(read_xml(xml_node), xml_child, level1 = "a", level2 = "b", pointer = TRUE), "pugi_xml"))
expect_true(inherits(xml_append_child3(read_xml(xml_node), xml_child, level1 = "a", level2 = "b", pointer = TRUE), "pugi_xml"))
})
test_that("set_sst", {
exp <- "a"
expect_equal(exp, set_sst("a"))
})
test_that("col2int and int2col", {
test <- "B"
x <- col2int(test)
that <- int2col(x)
expect_equal(test, that)
test <- "AABWAWD"
x <- col2int(test)
that <- int2col(x)
expect_equal(test, that)
x <- col_to_int(test)
that <- int_to_col(x)
expect_equal(test, that)
})
test_that("is_xml", {
expect_true(is_xml(""))
expect_false(is_xml("a"))
})
test_that("getXMLPtr1con", {
xml <- ""
got <- getXMLPtr1con(read_xml(xml))
exp <- c("", "", "")
expect_equal(got, exp)
})
test_that("write_xmlPtr", {
xml <- read_xml("")
temp <- tempfile(fileext = ".xml")
expect_silent(write_xmlPtr(xml, temp))
skip_on_cran()
expect_error(write_xmlPtr(xml, paste0("/", random_string(), "/test.xml")), "could not save file")
})