mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 18:24:09 +02:00
snapshot tests
This commit is contained in:
parent
a18068e957
commit
fbe3eee614
8 changed files with 1603 additions and 5 deletions
|
|
@ -28,6 +28,8 @@ once_cell = "1.17.1"
|
||||||
criterion = "0.4"
|
criterion = "0.4"
|
||||||
iai = "0.1"
|
iai = "0.1"
|
||||||
miette = { version = "5.5.0", features = ["fancy"] }
|
miette = { version = "5.5.0", features = ["fancy"] }
|
||||||
|
insta = { version = "1.28.0", features = ["json"] }
|
||||||
|
test-case = "3.0.0"
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "bench"
|
name = "bench"
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
hyperfine
|
hyperfine
|
||||||
cargo-expand
|
cargo-expand
|
||||||
rustup
|
rustup
|
||||||
|
cargo-insta
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,12 @@ impl<T: PartialEq> PartialEq for ClassMap<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> From<ClassMap<T>> for [T; 10] {
|
||||||
|
fn from(value: ClassMap<T>) -> Self {
|
||||||
|
value.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Optimized subject id
|
/// Optimized subject id
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Ord, PartialOrd, Hash)]
|
#[derive(Copy, Clone, Eq, PartialEq, Debug, Ord, PartialOrd, Hash)]
|
||||||
pub enum SubjectId {
|
pub enum SubjectId {
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ use std::collections::BTreeMap;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Default, PartialEq)]
|
#[derive(Debug, Serialize, Default, PartialEq)]
|
||||||
pub struct ClassStats {
|
pub struct ClassStats {
|
||||||
kills: ClassMap<u8>,
|
pub kills: ClassMap<u8>,
|
||||||
deaths: ClassMap<u8>,
|
pub deaths: ClassMap<u8>,
|
||||||
assists: ClassMap<u8>,
|
pub assists: ClassMap<u8>,
|
||||||
damage: ClassMap<u16>,
|
pub damage: ClassMap<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
||||||
|
|
@ -32,3 +32,12 @@ impl PlayerSpecificData for HealSpread {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoIterator for HealSpread {
|
||||||
|
type Item = (SteamId3, u32);
|
||||||
|
type IntoIter = <BTreeMap<SteamId3, u32> as IntoIterator>::IntoIter;
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
self.0.into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ macro_rules! handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct [<$name PerSubjectOutput>] {
|
pub struct [<$name PerSubjectOutput>] {
|
||||||
pub $($child: <$ty as $crate::EventHandler>::PerSubjectOutput),*
|
$(pub $child: <$ty as $crate::EventHandler>::PerSubjectOutput),*
|
||||||
}
|
}
|
||||||
|
|
||||||
impl serde::Serialize for [<$name PerSubjectOutput>] {
|
impl serde::Serialize for [<$name PerSubjectOutput>] {
|
||||||
|
|
|
||||||
66
tests/snapshot.rs
Normal file
66
tests/snapshot.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
use serde::Serialize;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use std::fs::read_to_string;
|
||||||
|
use test_case::test_case;
|
||||||
|
use tf_log_parser::module::{ClassStats, MedicStats};
|
||||||
|
use tf_log_parser::{parse, EventHandler, LogHandler, LogHandlerPerSubjectOutput};
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct LogResult {
|
||||||
|
global: <LogHandler as EventHandler>::GlobalOutput,
|
||||||
|
per_player: BTreeMap<String, LogPlayerData>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct LogPlayerData {
|
||||||
|
stats: ClassStatsRaw,
|
||||||
|
heals: BTreeMap<String, u32>,
|
||||||
|
medic: MedicStats,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<LogHandlerPerSubjectOutput> for LogPlayerData {
|
||||||
|
fn from(value: LogHandlerPerSubjectOutput) -> Self {
|
||||||
|
LogPlayerData {
|
||||||
|
stats: value.class_stats.into(),
|
||||||
|
medic: value.medic_stats,
|
||||||
|
heals: value
|
||||||
|
.heal_spread
|
||||||
|
.into_iter()
|
||||||
|
.map(|(user, heals)| (user.0.steam3(), heals))
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct ClassStatsRaw {
|
||||||
|
kills: [u8; 10],
|
||||||
|
deaths: [u8; 10],
|
||||||
|
assists: [u8; 10],
|
||||||
|
damage: [u16; 10],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ClassStats> for ClassStatsRaw {
|
||||||
|
fn from(value: ClassStats) -> Self {
|
||||||
|
ClassStatsRaw {
|
||||||
|
kills: value.kills.into(),
|
||||||
|
deaths: value.deaths.into(),
|
||||||
|
assists: value.assists.into(),
|
||||||
|
damage: value.damage.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case("log_2892242.log")]
|
||||||
|
fn test_parse(input: &str) {
|
||||||
|
let content = read_to_string(&format!("test_data/{}", input)).unwrap();
|
||||||
|
let (global, per_player) = parse(&content).unwrap();
|
||||||
|
let log = LogResult {
|
||||||
|
global,
|
||||||
|
per_player: per_player
|
||||||
|
.into_iter()
|
||||||
|
.map(|(key, value)| (key.0.steam3(), value.into()))
|
||||||
|
.collect(),
|
||||||
|
};
|
||||||
|
insta::assert_json_snapshot!(log);
|
||||||
|
}
|
||||||
1514
tests/snapshots/snapshot__parse.snap
Normal file
1514
tests/snapshots/snapshot__parse.snap
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue