use serde_derive::{Serialize, Deserialize}; #[derive(Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct Config { /// used in the window title bar name: Option, 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, /// 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()), version: (0, 0) }; 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()), version: (0, 0) }).unwrap(); let expected = include_str!("test-resources/basic/game.toml"); assert_eq!(&output, expected); } }