use std::{
fs::File,
io::{BufRead, BufReader, Seek},
path::Path,
};
use crate::{
output::{
Text,
drivers::text::{Emphasis, TextRenderer},
pivot::tests::assert_lines_eq,
},
spv::SpvArchive,
};
#[test]
fn text1() {
test_raw_spvfile("text1", None);
}
#[test]
fn light1() {
test_raw_spvfile("light1", None);
}
#[test]
fn light2() {
test_raw_spvfile("light2", None);
}
#[test]
fn light3() {
test_raw_spvfile("light3", None);
}
#[test]
fn light4() {
test_raw_spvfile("light4", None);
}
#[test]
fn light5() {
test_raw_spvfile("light5", None);
}
#[test]
fn light6() {
test_raw_spvfile("light6", None);
}
#[test]
fn light7() {
test_raw_spvfile("light7", None);
}
#[test]
fn light8() {
test_raw_spvfile("light8", None);
}
#[test]
fn legacy1() {
test_raw_spvfile("legacy1", None);
}
#[test]
fn legacy2() {
test_raw_spvfile("legacy2", None);
}
#[test]
fn legacy3() {
test_raw_spvfile("legacy3", None);
}
#[test]
fn legacy4() {
test_raw_spvfile("legacy4", None);
}
#[test]
fn legacy5() {
test_raw_spvfile("legacy5", None);
}
#[test]
fn legacy6() {
test_raw_spvfile("legacy6", None);
}
#[test]
fn legacy7() {
test_raw_spvfile("legacy7", None);
}
#[test]
fn legacy8() {
test_raw_spvfile("legacy8", None);
}
#[test]
fn legacy9() {
test_raw_spvfile("legacy9", None);
}
#[test]
fn legacy10() {
test_raw_spvfile("legacy10", None);
}
#[test]
fn legacy11() {
test_raw_spvfile("legacy11", None);
}
#[test]
fn legacy12() {
test_raw_spvfile("legacy12", None);
}
#[test]
fn legacy13() {
test_raw_spvfile("legacy13", None);
}
#[test]
fn legacy14() {
test_raw_spvfile("legacy14", None);
}
#[test]
fn legacy15() {
test_raw_spvfile("legacy15", None);
}
#[test]
fn legacy16() {
test_raw_spvfile("legacy16", None);
}
#[test]
fn legacy17() {
test_raw_spvfile("legacy17", Some(Emphasis::Ansi));
}
fn test_raw_spvfile(name: &str, emphasis: Option<Emphasis>) {
let input_filename = Path::new("src/spv/testdata")
.join(name)
.with_extension("spv");
let spvfile = BufReader::new(File::open(&input_filename).unwrap());
let expected_filename = input_filename.with_extension("expected");
let expected = String::from_utf8(std::fs::read(&expected_filename).unwrap()).unwrap();
test_spvfile(spvfile, &expected, &expected_filename, emphasis);
}
fn test_spvfile<R>(spvfile: R, expected: &str, expected_filename: &Path, emphasis: Option<Emphasis>)
where
R: BufRead + Seek + 'static,
{
let mut warnings = Vec::new();
let result = match SpvArchive::open_reader(spvfile, None) {
Ok(mut archive) => archive.read(|w| warnings.push(w)),
Err(error) => Err(error),
};
let output = match result {
Ok(spv_file) => {
let (items, _page_setup ) = spv_file.into_contents();
let mut output = Vec::new();
output.extend(items);
output.into_iter().collect()
}
Err(error) => Text::new_log(error.to_string()).into_item(),
};
let mut renderer = TextRenderer::default().with_emphasis(emphasis);
let mut actual = String::new();
renderer.render(&output, &mut actual).unwrap();
if expected != actual {
if std::env::var("PSPP_REFRESH_EXPECTED").is_ok() {
std::fs::write(expected_filename, actual).unwrap();
panic!("{}: refreshed output", expected_filename.display());
} else {
eprintln!("note: rerun with PSPP_REFRESH_EXPECTED=1 to refresh expected output");
}
}
assert_lines_eq(&expected, expected_filename.display(), &actual, "actual");
}