R/are_equal_xml_lines.R

Defines functions are_equal_xml_lines

#' Determine if XML lines result in equal trees
#' @param lines_1 lines of a first XML file
#' @param lines_2 lines of a second XML file
#' @param section name of an XML section.
#'   Assumes that there is one line that starts with \code{<section}
#'   (excluding whitespace)
#'   and one line that is \code{</section>} (also excluding whitespace)
#' @return TRUE if the two sections of the XML files are equal,
#'   FALSE otherwise
#' @author Richèl J.C. Bilderbeek
#' @noRd
are_equal_xml_lines <- function(
  lines_1,
  lines_2,
  section
) {
  if (!has_xml_opening_tag(lines = lines_1, section = section)) {
    stop(
      "Opening tag for 'section' could not be found in 'lines_1', ",
      "'section' has value '", section, "'"
    )
  }
  if (!has_xml_closing_tag(lines = lines_1, section = section)) {
    stop(
      "Closing tag for 'section' could not be found in 'lines_1', ",
      "'section' has value '", section, "'"
    )
  }
  if (!has_xml_opening_tag(lines = lines_2, section = section)) {
    stop(
      "Opening tag for 'section' could not be found in 'lines_2', ",
      "'section' has value '", section, "'"
    )
  }
  if (!has_xml_closing_tag(lines = lines_2, section = section)) {
    stop(
      "Closing tag for 'section' could not be found in 'lines_2', ",
      "'section' has value '", section, "'"
    )
  }
  section_1 <- extract_xml_section_from_lines(
    lines = lines_1, section = section)
  section_2 <- extract_xml_section_from_lines(
    lines = lines_2, section = section)
  identical(section_1, section_2)
}
ropensci/beautier documentation built on March 12, 2019, 8:27 p.m.