1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 10:14:06 +02:00

message type testing

This commit is contained in:
Robin Appelman 2019-04-07 19:13:39 +02:00
commit 2602e23de8
8 changed files with 101 additions and 17 deletions

View file

@ -1,7 +1,7 @@
use std::fs;
use pretty_assertions::assert_eq;
use tf_demo_parser::{Demo, DemoParser, MatchState};
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");
@ -12,6 +12,23 @@ fn snapshot_test(input_file: &str, snapshot_file: &str) {
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");
@ -25,4 +42,9 @@ fn snapshot_test_gully() {
#[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");
}