knitr::opts_chunk$set( error = TRUE, collapse = TRUE, comment = "#>", out.width = "100%" )
library(testthat) library(jeksterslabRutils) context("Test util_xml2list.")
tmp <- util_make_subdir()
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 )
results <- util_xml2list( tags = tags, con = fn, par = FALSE )
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 )
test_that("title is correct", { expect_equivalent( results[, "TITLE"], title ) })
test_that("artist is correct", { expect_equivalent( results[, "ARTIST"], artist ) })
test_that("country is correct", { expect_equivalent( results[, "COUNTRY"], country ) })
test_that("company is correct", { expect_equivalent( results[, "COMPANY"], company ) })
test_that("price is correct", { expect_equivalent( results[, "PRICE"], price ) })
test_that("year is correct", { expect_equivalent( results[, "YEAR"], year ) })
util_clean_dir( dir = tmp, create_dir = FALSE )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.