peachy/src/config.rs

50 lines
1.4 KiB
Rust
Raw Normal View History

use serde_derive::{Serialize, Deserialize};
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Config {
/// used in the window title bar
pub name: Option<String>,
pub width: u8,
pub height: u8,
/// animation rate in milliseconds
pub tick: u64,
/// if this is not specified, the game will pick the first room it finds
pub starting_room: Option<String>,
/// major / minor
pub version: (u8, u8),
}
#[cfg(test)]
mod test {
use crate::Config;
#[test]
fn test_config_from_toml() {
let output: Config = toml::from_str(include_str!("test-resources/basic/game.toml")).unwrap();
let expected = Config {
name: Some("Write your game's title here".to_string()),
width: 16,
height: 9,
tick: 400,
starting_room: Some("example room".to_string()),
2021-05-17 14:10:59 +00:00
version: (0, 1)
};
assert_eq!(output, expected);
}
#[test]
fn test_config_to_toml() {
let output = toml::to_string(&Config {
name: Some("Write your game's title here".to_string()),
width: 16,
height: 9,
tick: 400,
starting_room: Some("example room".to_string()),
2021-05-17 14:10:59 +00:00
version: (0, 1)
}).unwrap();
let expected = include_str!("test-resources/basic/game.toml");
assert_eq!(&output, expected);
}
}