#' Helper function to remove UUID #' #' Removes a pattern matching a UUID from a character. #' This allows the output from write_eml() - which generates a different UUID #' for every run - to be compared against a snapshot. #' @param character Character vector from which UUID should be removed. #' @param replacement Optional replacement character. #' @return A character vector with the UUIDs removed. #' @examples #' to_clean <- paste( #' 'encoding=\"UTF-8\"?>",', #' '"% xml2::as_list() xml_file_location <- purrr::chuck(xml_list, "archive", core_or_extension, "files", "location") %>% unlist() xml_file_fields <- xml_list %>% purrr::chuck("archive", core_or_extension) %>% purrr::map_dfr(~ dplyr::tibble( index = as.numeric(attr(.x, which = "index")), term = attr(.x, which = "term") )) %>% dplyr::filter(!is.na(term)) %>% dplyr::mutate(field = basename(term), .keep = "unused") # Get fields from csv csv_file_cols <- readr::read_csv(file, show_col_types = FALSE) %>% colnames() %>% purrr::map_chr(~ sub("^[A-Za-z]+:", "", .x)) # Remove namespace like "dcterms:" csv_file_fields <- dplyr::tibble(field = csv_file_cols) %>% dplyr::mutate(index = as.integer(rownames(.)) - 1, .before = field) # Add index # Compare testthat::expect_identical(csv_file_fields, xml_file_fields, ) testthat::expect_identical(basename(file), xml_file_location) }