mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
switch to cargo-insta for snapshot testing
This commit is contained in:
parent
d20fbb8e37
commit
07039da23d
23 changed files with 42991 additions and 22877 deletions
|
|
@ -1,11 +1,10 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
use std::fs::{self, File};
|
||||
use std::fs;
|
||||
use test_case::test_case;
|
||||
|
||||
use fnv::FnvHashMap;
|
||||
use std::collections::HashMap;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use tf_demo_parser::demo::data::DemoTick;
|
||||
use tf_demo_parser::demo::message::packetentities::{EntityId, PacketEntity, UpdateType};
|
||||
use tf_demo_parser::demo::message::Message;
|
||||
|
|
@ -134,86 +133,15 @@ impl MessageHandler for EntityDumper {
|
|||
}
|
||||
}
|
||||
|
||||
#[test_case("test_data/small.dem", "test_data/small_entities.json"; "small.dem")]
|
||||
fn entity_test(input_file: &str, snapshot_file: &str) {
|
||||
#[test_case("test_data/small.dem")]
|
||||
fn entity_test(input_file: &str) {
|
||||
let file = fs::read(input_file).expect("Unable to read file");
|
||||
let demo = Demo::new(&file);
|
||||
let (_, entities) = DemoParser::new_with_analyser(demo.get_stream(), EntityDumper::new())
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let json_file = File::open(snapshot_file).expect("Unable to read file");
|
||||
let mut reader = BufReader::new(json_file);
|
||||
let mut buffer = String::new();
|
||||
|
||||
let mut expected = Vec::with_capacity(128);
|
||||
|
||||
while reader.read_line(&mut buffer).expect("failed to read line") > 0 {
|
||||
let entity: EntityDump =
|
||||
serde_json::from_str(buffer.trim_end()).expect("failed to parse json");
|
||||
expected.push(entity);
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
pretty_assertions::assert_eq!(expected.len(), entities.len());
|
||||
|
||||
let entity_ids: Vec<_> = entities.iter().map(|entity| entity.id).collect();
|
||||
let expected_ids: Vec<_> = expected.iter().map(|entity| entity.id).collect();
|
||||
|
||||
pretty_assertions::assert_eq!(expected_ids, entity_ids);
|
||||
|
||||
for (expected_entity, entity) in expected.into_iter().zip(entities.into_iter()) {
|
||||
pretty_assertions::assert_eq!(
|
||||
expected_entity.tick,
|
||||
entity.tick,
|
||||
"Failed comparing entity {}",
|
||||
entity.id
|
||||
);
|
||||
pretty_assertions::assert_eq!(
|
||||
expected_entity.id,
|
||||
entity.id,
|
||||
"Failed comparing entity {}",
|
||||
entity.id
|
||||
);
|
||||
pretty_assertions::assert_eq!(
|
||||
expected_entity.server_class,
|
||||
entity.server_class,
|
||||
"Failed comparing entity {}",
|
||||
entity.id
|
||||
);
|
||||
pretty_assertions::assert_eq!(
|
||||
expected_entity.pvs,
|
||||
entity.pvs,
|
||||
"Failed comparing entity {}",
|
||||
entity.id
|
||||
);
|
||||
let mut prop_names: Vec<_> = entity.props.keys().collect();
|
||||
let mut expected_prop_names: Vec<_> = expected_entity.props.keys().collect();
|
||||
prop_names.sort();
|
||||
expected_prop_names.sort();
|
||||
|
||||
pretty_assertions::assert_eq!(
|
||||
expected_prop_names,
|
||||
prop_names,
|
||||
"Failed comparing entity {}",
|
||||
entity.id
|
||||
);
|
||||
|
||||
for prop_name in expected_prop_names {
|
||||
pretty_assertions::assert_eq!(
|
||||
expected_entity.props.get(prop_name),
|
||||
entity.props.get(prop_name),
|
||||
"Failed comparing entity {} prop {}",
|
||||
entity.id,
|
||||
prop_name
|
||||
);
|
||||
}
|
||||
|
||||
pretty_assertions::assert_eq!(
|
||||
expected_entity,
|
||||
entity,
|
||||
"Failed comparing entity {}",
|
||||
entity.id
|
||||
);
|
||||
}
|
||||
insta::with_settings!({sort_maps =>true}, {
|
||||
insta::assert_json_snapshot!(entities);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue