use config_tools::{sectioned_defaults, Config, FromSection, Section};
#[derive(Debug, FromSection, PartialEq)]
struct ServerSettings {
address: String,
port: u16,
threads: u16,
}
#[test]
fn test_incomplete_section_parsing() {
let config = Config::load_or_default(
"nonexistent.ini",
sectioned_defaults! {
["Server"] {
"address" => "192.168.1.1", }
},
);
let server_settings_result = ServerSettings::from_section(&config.section("Server").unwrap());
assert!(
server_settings_result.is_err(),
"Parsing an incomplete section should result in an error"
);
}
#[test]
fn test_section_parsing_into_struct() {
let config = Config::load_or_default(
"nonexistent.ini",
sectioned_defaults! {
["Server"] {
"address" => "192.168.1.1",
"port" => "8000",
"threads" => "8",
}
},
);
let server_settings = ServerSettings::from_section(&config.section("Server").unwrap()).unwrap();
let expected_settings = ServerSettings {
address: "192.168.1.1".to_string(),
port: 8000,
threads: 8,
};
assert_eq!(server_settings, expected_settings);
}