#![allow(unused)]
use std::ffi::OsString;
use std::fs;
use std::path::Path;
use insta::{assert_debug_snapshot, assert_snapshot, with_settings};
use mlt_core::test_helpers::{dec, parser};
use test_each_file::test_each_path;
fn parse([path]: [&Path; 1]) {
let mut snapshot_path = OsString::from("snapshots-");
snapshot_path.push(path.parent().unwrap().file_name().unwrap());
with_settings! {
{ omit_expression => true,
snapshot_path => snapshot_path ,
prepend_module_to_snapshot => false },
{
parse_one_file(path);
}
}
}
fn parse_one_file(path: impl AsRef<Path>) {
let path = path.as_ref();
eprintln!("Parsing MLT file: {}", path.display());
let file_name = path.file_stem().unwrap().to_string_lossy().to_string();
let buffer = fs::read(path).unwrap();
let mut p = parser();
let mut d = dec();
match p.parse_layers(&buffer) {
Ok(layers) => {
assert_snapshot!(p.reserved(), @"");
assert_debug_snapshot!(format!("{file_name}-parsed"), layers);
let mut decoded = Vec::with_capacity(layers.len());
for (idx, layer) in layers.into_iter().enumerate() {
match layer.decode_all(&mut d) {
Ok(l) => decoded.push(l),
Err(e) => {
let idx = if idx == 0 {
String::new()
} else {
format!("_{idx}")
};
assert_debug_snapshot!(format!("{file_name}{idx}___bad-decode"), e);
break;
}
}
}
assert_snapshot!(d.consumed(), @"");
assert_debug_snapshot!(format!("{file_name}-decoded"), decoded);
}
Err(e) => {
let filesize = buffer.len();
assert_debug_snapshot!(format!("{file_name}___bad___{filesize}"), e);
}
}
}
#[test]
#[ignore = "used for manual testing of a single file"]
fn test_plain() {
let path = "../../test/expected/tag0x01/omt/11_1062_1368.mlt";
let path = Path::new(path);
let buffer = fs::read(path).unwrap();
let mut p = parser();
let layers = p.parse_layers(&buffer).unwrap();
assert_snapshot!(p.reserved(), @"");
let _ = layers;
}