Skip to content

Commit

Permalink
Handle unusual team ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantaylor committed Sep 16, 2024
1 parent 1dd9c87 commit 03a676e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Binary file added replays/unusual_team_id.rec
Binary file not shown.
1 change: 1 addition & 0 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl TryFrom<u32> for Team {
match input {
0 => Ok(Team::First),
1 => Ok(Team::Second),
10000 => Ok(Team::Second),
_ => Err(format!("Invalid team ID {}!", input)),
}
}
Expand Down
27 changes: 26 additions & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
thread,
};
use uuid::{uuid, Uuid};
use vault::{Command, CommandType, Faction, GameType, Replay};
use vault::{Command, CommandType, Faction, GameType, Replay, Team};

#[test]
fn parse_success() {
Expand Down Expand Up @@ -188,6 +188,31 @@ fn parse_unusual_brit_faction() {
);
}

#[test]
fn parse_unusual_team_id() {
let data = include_bytes!("../replays/unusual_team_id.rec");
let replay = Replay::from_bytes(data);
assert!(replay.is_ok());
let unwrapped = replay.unwrap();
assert_eq!(
unwrapped
.players()
.iter()
.map(|player| { player.team() })
.collect::<Vec<Team>>(),
vec![
Team::First,
Team::Second,
Team::First,
Team::Second,
Team::First,
Team::Second,
Team::First,
Team::Second
]
);
}

#[test]
#[cfg_attr(not(feature = "regression"), ignore)]
fn regression() {
Expand Down

0 comments on commit 03a676e

Please sign in to comment.