use mj::core::config::*; use std::path::Path; #[test] fn serialize_config() { let config = Config { global_vault_root: Path::new("/tmp").to_path_buf(), view_delimiter: String::from("¶"), input_delimiter: String::from("::"), task_not_done_prefix: String::from("-"), task_not_done_display_prefix: String::from("⇡"), task_in_progress_prefix: String::from("*"), task_in_progress_display_prefix: String::from("↝"), task_done_prefix: String::from("+"), task_done_display_prefix: String::from("↷"), }; let expected = r#"global_vault_root = '/tmp' view_delimiter = '¶' input_delimiter = '::' task_not_done_prefix = '-' task_not_done_display_prefix = '⇡' task_in_progress_prefix = '*' task_in_progress_display_prefix = '↝' task_done_prefix = '+' task_done_display_prefix = '↷' "#; let toml = config.serialize(); assert!(toml.is_some()); let toml = toml.unwrap(); assert_eq!(expected, toml); } #[test] fn deserialize_config() { let toml = r#"global_vault_root = '/tmp' view_delimiter = '¶' input_delimiter = '::' task_not_done_prefix = '-' task_not_done_display_prefix = '⇡' task_in_progress_prefix = '*' task_in_progress_display_prefix = '↝' task_done_prefix = '+' task_done_display_prefix = '↷' "#; let config = Config::deserialize(toml); assert!(config.is_some()); let config = config.unwrap(); assert_eq!(Path::new("/tmp"), config.global_vault_root); } #[test] fn reserialize_config() { let input = Config { global_vault_root: Path::new("/tmp").to_path_buf(), view_delimiter: String::from("¶"), input_delimiter: String::from("::"), task_not_done_prefix: String::from("-"), task_not_done_display_prefix: String::from("⇡"), task_in_progress_prefix: String::from("*"), task_in_progress_display_prefix: String::from("↝"), task_done_prefix: String::from("+"), task_done_display_prefix: String::from("↷"), }; let toml = input.serialize(); assert!(toml.is_some()); let toml = toml.unwrap(); let output = Config::deserialize(toml.as_str()); assert!(&output.is_some()); let output = output.unwrap(); assert_eq!(&input.global_vault_root, &output.global_vault_root); assert_eq!(Path::new("/tmp"), &output.global_vault_root); }