diff --git a/Cargo.toml b/Cargo.toml index 9d86fd31..6e31cd7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,7 @@ pathdiff = "0.2" [dev-dependencies] serde_derive = "1.0.8" +serde_yaml = "0.9" float-cmp = "0.9" chrono = { version = "0.4", features = ["serde"] } tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "io-util", "time"]} diff --git a/tests/Settings.yaml b/tests/Settings.yaml index c7b1549c..10ec3cc1 100644 --- a/tests/Settings.yaml +++ b/tests/Settings.yaml @@ -15,3 +15,4 @@ place: # For override tests FOO: FOO should be overridden bar: I am bar +192.168.1.1: a string value diff --git a/tests/file_yaml.rs b/tests/file_yaml.rs index b961c2a6..2fea07ff 100644 --- a/tests/file_yaml.rs +++ b/tests/file_yaml.rs @@ -26,6 +26,8 @@ struct Settings { place: Place, #[serde(rename = "arr")] elements: Vec, + #[serde(rename = "192.168.1.1")] + ip_key: String, } fn make() -> Config { @@ -35,6 +37,35 @@ fn make() -> Config { .unwrap() } +#[test] +fn test_keys_with_periods_deserialize_serde_yaml() { + let map = "192.168.1.1: a string value"; + + let c: HashMap = serde_yaml::from_str(map).unwrap(); + + assert_eq!(c.get("192.168.1.1").unwrap(), "a string value"); +} + +#[test] +fn test_keys_with_periods_deserialize_yaml_rust() { + use yaml_rust::YamlLoader; + + let map = "192.168.1.1: a string value"; + + let c = YamlLoader::load_from_str(map).unwrap().first().unwrap().clone(); + + assert_eq!(c["192.168.1.1"].as_str().unwrap(), "a string value"); +} + +#[test] +fn test_keys_with_periods_deserialize() { + let c = make(); + + let s: Settings = c.try_deserialize().unwrap(); + + assert_eq!(s.ip_key, "a string value"); +} + #[test] fn test_file() { let c = make();