Add pretty-assertions to dev deps

main
Adrian 2 years ago
parent 635d8a0eb0
commit 74842c7f17

@ -21,3 +21,4 @@ tl = "0.6.2"
[dev-dependencies]
tokio = { version = "1.16.1", features = ["macros", "time"] }
pretty_assertions = "1.1.0"

@ -39,7 +39,7 @@ pub struct Team {
}
/// Basic information about a team.
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct Event {
/// HLTV-associated ID (found in the URL of the event page).
pub id: u32,
@ -120,7 +120,7 @@ pub struct Score {
/// Contains detailed information about a match. Corresponds to data found on [HLTV's
/// match page](https://www.hltv.org/matches/2239492/nip-vs-virtuspro-sltv-starseries-v-finals).
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct MatchPage {
/// ID of the match
pub id: u32,
@ -149,7 +149,7 @@ pub struct MatchPage {
}
/// Current status of a match.
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum MatchStatus {
Upcoming,
Finished,
@ -167,14 +167,14 @@ pub enum WhichTeam {
/// A match score refers to the number of won maps of both team 1 and team 2.
/// Examples are `1-0`, `2-1`, `1-3`, etc.
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct MatchScore {
pub team1: u32,
pub team2: u32,
}
/// Represents the result of a single map. Examples are: `16-14`, `10-16`, `19-17`
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct MapScore {
pub map: Map,
/// Number of rounds won by team 1.
@ -184,11 +184,11 @@ pub struct MapScore {
}
/// A tuple of a specific players map performance.
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, PartialEq, Clone)]
pub struct Performance(pub Player, pub Stats);
/// Collection of performance metrics of a player.
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, PartialEq, Clone)]
pub struct Stats {
/// Total kills.
pub kills: u32,
@ -204,7 +204,7 @@ pub struct Stats {
/// All CSGO maps that are listed on HLTV
#[derive(Debug, Default)]
#[derive(Debug, Default, PartialEq)]
pub enum Map {
#[default]
Unknown,

@ -12,8 +12,7 @@ async fn wait() {
async fn get_match() -> Result<(), Box<dyn Error>> {
wait().await;
let req = hltv::get_match(2346065);
let res = req.fetch().await?;
println!("{:?}", res);
req.fetch().await?;
Ok(())
}

@ -0,0 +1,59 @@
use chrono::{DateTime, NaiveDateTime, Utc};
use hltv::data::*;
use pretty_assertions::assert_eq;
use std::error::Error;
use std::time::Duration;
async fn wait() {
tokio::time::sleep(Duration::from_millis(1500)).await;
}
/// Testing if specific matches are parsed without throwing errors
#[tokio::test]
async fn concluded_bo3() -> Result<(), Box<dyn Error>> {
wait().await;
// Bo3 with one 6 man Team
let res = hltv::get_match(2346065).fetch().await?;
assert_eq!(
res,
MatchPage {
id: 2346065,
status: MatchStatus::Finished,
team1: Some(Team {
id: 6665,
name: "Astralis".to_string()
}),
team2: Some(Team {
id: 9565,
name: "Vitality".to_string()
}),
event: Event {
id: 5206,
name: "BLAST Premier Global Final 2020".to_string()
},
date: DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(1611415800, 0), Utc),
format: MatchFormat::Bo3,
maps: vec![
MapScore {
map: Map::Dust2,
team1: 16,
team2: 14,
},
MapScore {
map: Map::Overpass,
team1: 10,
team2: 16,
},
MapScore {
map: Map::Inferno,
team1: 16,
team2: 5,
}
],
score: Some(MatchScore { team1: 2, team2: 1 }),
stats: vec![],
}
);
Ok(())
}
Loading…
Cancel
Save