don't try to get tiles with ID of zero; test this

This commit is contained in:
Max Bradbury 2020-06-24 15:30:16 +01:00
parent 5de02c5950
commit 93a50e6b86
1 changed files with 15 additions and 1 deletions

View File

@ -230,7 +230,7 @@ impl Game {
if ! avatar_exists {
return Err(NotFound::Avatar);
}
Ok(
Game {
name,
@ -318,6 +318,12 @@ impl Game {
let mut tile_ids = room.unwrap().tiles.clone();
tile_ids.sort();
tile_ids.dedup();
// remove 0 as this isn't a real tile
let zero_index = tile_ids.iter()
.position(|i| i == &"0".to_string());
if zero_index.is_some() {
tile_ids.remove(zero_index.unwrap());
}
// remove Ok once this function returns a result
Ok(self.get_tiles_by_ids(tile_ids))
}
@ -679,4 +685,12 @@ mod test {
game.version = Some(Version { major: 5, minor: 0 });
assert!(game.to_string().contains("# BITSY VERSION 5.0"))
}
#[test]
fn test_get_tiles_for_room() {
assert_eq!(
crate::mock::game_default().get_tiles_for_room("0".to_string()).unwrap(),
vec![&crate::mock::tile_default()]
)
}
}