Set test parameters

fn <- file.path(
  file.path(
    tmp,
    util_rand_str()
  )
)
title <- "Romanza"
artist <- "Andrea Bocelli"
country <- "EU"
company <- "Polydor"
price <- "10.80"
year <- "1996"
xml <- paste0(
  "<TITLE>",
  title,
  "</TITLE>",
  "<ARTIST>",
  artist,
  "</ARTIST>",
  "<COUNTRY>",
  country,
  "</COUNTRY>",
  "<COMPANY>",
  company,
  "</COMPANY>",
  "<PRICE>",
  price,
  "</PRICE>",
  "<YEAR>",
  year,
  "</YEAR>"
)
writeLines(
  text = xml,
  con = fn
)
tags <- c(
  "TITLE",
  "ARTIST",
  "COUNTRY",
  "COMPANY",
  "PRICE",
  "YEAR"
)
Variable <- c(
  "`title`",
  "`artist`",
  "`country`",
  "`company`",
  "`price`",
  "`year`"
)
Description <- c(
  "Title",
  "Artist",
  "Country",
  "Company",
  "Price",
  "Year"
)
Value <- c(
  title,
  artist,
  country,
  company,
  price,
  year
)
knitr::kable(
  x = data.frame(
    Variable,
    Description,
    Value
  ),
  row.names = FALSE
)
Variable Description Value
title Title Romanza
artist Artist Andrea Bocelli
country Country EU
company Company Polydor
price Price 10.80
year Year 1996
results <- util_xml2list(
  tags = tags,
  con = fn,
  par = FALSE
)

Results

Parameter <- c(
  title,
  artist,
  country,
  company,
  price,
  year
)
Result <- c(
  results[, "TITLE"],
  results[, "ARTIST"],
  results[, "COUNTRY"],
  results[, "COMPANY"],
  results[, "PRICE"],
  results[, "YEAR"]
)
knitr::kable(
  x = data.frame(
    Description,
    Parameter,
    Result
  ),
  row.names = FALSE
)
Description Parameter Result
Title Romanza Romanza
Artist Andrea Bocelli Andrea Bocelli
Country EU EU
Company Polydor Polydor
Price 10.80 10.80
Year 1996 1996
test_that("title is correct", {
  expect_equivalent(
    results[, "TITLE"],
    title
  )
})
#> Test passed 😸
test_that("artist is correct", {
  expect_equivalent(
    results[, "ARTIST"],
    artist
  )
})
#> Test passed 🎉
test_that("country is correct", {
  expect_equivalent(
    results[, "COUNTRY"],
    country
  )
})
#> Test passed 🌈
test_that("company is correct", {
  expect_equivalent(
    results[, "COMPANY"],
    company
  )
})
#> Test passed 🥳
test_that("price is correct", {
  expect_equivalent(
    results[, "PRICE"],
    price
  )
})
#> Test passed 🌈
test_that("year is correct", {
  expect_equivalent(
    results[, "YEAR"],
    year
  )
})
#> Test passed 🥳

Clean up temporary files and folders

util_clean_dir(
  dir = tmp,
  create_dir = FALSE
)