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
name: Option<String>,
width: u8,
height: u8,
/// animation rate in milliseconds
tick: u64,
/// if this is not specified, the game will pick the first room it finds
starting_room: Option<String>,
/// major / minor
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);
}
}