mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
50 lines
No EOL
1.7 KiB
Rust
50 lines
No EOL
1.7 KiB
Rust
use std::fs;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use tf_demo_parser::{Demo, DemoParser, MatchState, MessageTypeAnalyser, MessageType};
|
|
|
|
fn snapshot_test(input_file: &str, snapshot_file: &str) {
|
|
let file = fs::read(input_file).expect("Unable to read file");
|
|
let demo = Demo::new(file);
|
|
let (_, state) = DemoParser::parse_demo(demo.get_stream()).unwrap();
|
|
|
|
let expected: MatchState = serde_json::from_slice(fs::read(snapshot_file).expect("Unable to read file").as_slice()).unwrap();
|
|
assert_eq!(expected, state);
|
|
}
|
|
|
|
fn test_message_types(input_file: &str, snapshot_file: &str) {
|
|
let file = fs::read(input_file).expect("Unable to read file");
|
|
let demo = Demo::new(file);
|
|
let (_, message_types) = DemoParser::parse_with_analyser(demo.get_stream(), MessageTypeAnalyser::new()).unwrap();
|
|
|
|
let expected: Vec<MessageType> = serde_json::from_slice(fs::read(snapshot_file).expect("Unable to read file").as_slice()).unwrap();
|
|
assert_eq!(expected, message_types);
|
|
}
|
|
|
|
fn dump_message_types(input_file: &str, snapshot_file: &str) {
|
|
let file = fs::read(input_file).expect("Unable to read file");
|
|
let demo = Demo::new(file);
|
|
let (_, message_types) = DemoParser::parse_with_analyser(demo.get_stream(), MessageTypeAnalyser::new()).unwrap();
|
|
|
|
fs::write(snapshot_file, serde_json::to_vec(&message_types).unwrap()).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_test_small() {
|
|
snapshot_test("data/small.dem", "data/small.json");
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_test_gully() {
|
|
snapshot_test("data/gully.dem", "data/gully.json");
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_test_comp() {
|
|
snapshot_test("data/comp.dem", "data/comp.json");
|
|
}
|
|
|
|
#[test]
|
|
fn message_type_test_comp() {
|
|
dump_message_types("data/comp.dem", "data/comp_message_types.json");
|
|
} |