mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
cleanup tests
This commit is contained in:
parent
e196b7bfcc
commit
acc1584524
5 changed files with 70 additions and 123 deletions
|
|
@ -1,9 +1,16 @@
|
|||
use pretty_assertions::assert_eq;
|
||||
use std::fs;
|
||||
use test_case::test_case;
|
||||
|
||||
use tf_demo_parser::demo::parser::gamestateanalyser::{GameState, GameStateAnalyser};
|
||||
use tf_demo_parser::{Demo, DemoParser, MatchState, MessageType, MessageTypeAnalyser};
|
||||
use tf_demo_parser::{Demo, DemoParser, MatchState};
|
||||
|
||||
#[test_case("data/small.dem", "data/small.json"; "small.dem")]
|
||||
#[test_case("data/gully.dem", "data/gully.json"; "gully.dem")]
|
||||
#[test_case("data/comp.dem", "data/comp.json"; "comp.dem")]
|
||||
#[test_case("data/malformed_cvar.dem", "data/malformed_cvar.json"; "malformed_cvar.dem")]
|
||||
#[test_case("data/unicode-saytext.dem", "data/unicode-saytext.json"; "unicode-saytext.dem")]
|
||||
#[test_case("data/nousers.dem", "data/nousers.json"; "nousers.dem")]
|
||||
#[test_case("data/decal.dem", "data/decal.json"; "decal.dem")]
|
||||
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);
|
||||
|
|
@ -15,26 +22,11 @@ fn snapshot_test(input_file: &str, snapshot_file: &str) {
|
|||
.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::new_with_analyser(demo.get_stream(), MessageTypeAnalyser::default())
|
||||
.parse()
|
||||
.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);
|
||||
pretty_assertions::assert_eq!(expected, state);
|
||||
}
|
||||
|
||||
#[test_case("data/small.dem", "data/small_game_state.json"; "small.dem")]
|
||||
#[test_case("data/gully.dem", "data/gully_game_state.json"; "gully.dem")]
|
||||
fn game_state_test(input_file: &str, snapshot_file: &str) {
|
||||
let file = fs::read(input_file).expect("Unable to read file");
|
||||
let demo = Demo::new(file);
|
||||
|
|
@ -48,50 +40,5 @@ fn game_state_test(input_file: &str, snapshot_file: &str) {
|
|||
.as_slice(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(expected, state);
|
||||
}
|
||||
|
||||
#[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 snapshot_test_malformed_cvar() {
|
||||
snapshot_test("data/malformed_cvar.dem", "data/malformed_cvar.json");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_test_unicode_chat() {
|
||||
snapshot_test("data/unicode-saytext.dem", "data/unicode-saytext.json");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_test_player_in_update() {
|
||||
snapshot_test("data/nousers.dem", "data/nousers.json");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_test_decal() {
|
||||
snapshot_test("data/decal.dem", "data/decal.json");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn game_state_test_small() {
|
||||
game_state_test("data/small.dem", "data/small_game_state.json");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn game_state_test_gully() {
|
||||
game_state_test("data/gully.dem", "data/gully_game_state.json");
|
||||
pretty_assertions::assert_eq!(expected, state);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue