From 7ba954942ab9acd8b658636cf775c4360ec76272 Mon Sep 17 00:00:00 2001 From: Aleksey Ivanov Date: Mon, 9 Apr 2018 20:03:07 +0300 Subject: [Close #70] Support newtype struct deserialization --- tests/Settings.toml | 3 +++ tests/file_toml.rs | 10 ++++++++++ tests/get.rs | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/Settings.toml b/tests/Settings.toml index 2f2da74..14f881f 100644 --- a/tests/Settings.toml +++ b/tests/Settings.toml @@ -3,6 +3,8 @@ debug_s = "true" production = false production_s = "false" +code = 53 + # errors boolean_s_parse = "fals" @@ -15,6 +17,7 @@ name = "1" name = "2" [place] +number = 1 name = "Torre di Pisa" longitude = 43.7224985 latitude = 10.3970522 diff --git a/tests/file_toml.rs b/tests/file_toml.rs index f272698..2d8203f 100644 --- a/tests/file_toml.rs +++ b/tests/file_toml.rs @@ -11,6 +11,7 @@ use config::*; #[derive(Debug, Deserialize)] struct Place { + number: PlaceNumber, name: String, longitude: f64, latitude: f64, @@ -21,10 +22,17 @@ struct Place { rating: Option, } +#[derive(Debug, Deserialize, PartialEq)] +struct PlaceNumber(u8); + +#[derive(Debug, Deserialize, PartialEq)] +struct AsciiCode(i8); + #[derive(Debug, Deserialize)] struct Settings { debug: f64, production: Option, + code: AsciiCode, place: Place, #[serde(rename = "arr")] elements: Vec, @@ -47,6 +55,8 @@ fn test_file() { assert!(s.debug.approx_eq_ulps(&1.0, 2)); assert_eq!(s.production, Some("false".to_string())); + assert_eq!(s.code, AsciiCode(53)); + assert_eq!(s.place.number, PlaceNumber(1)); assert_eq!(s.place.name, "Torre di Pisa"); assert!(s.place.longitude.approx_eq_ulps(&43.7224985, 2)); assert!(s.place.latitude.approx_eq_ulps(&10.3970522, 2)); diff --git a/tests/get.rs b/tests/get.rs index 517339e..dac138c 100644 --- a/tests/get.rs +++ b/tests/get.rs @@ -107,7 +107,7 @@ fn test_map() { let c = make(); let m: HashMap = c.get("place").unwrap(); - assert_eq!(m.len(), 7); + assert_eq!(m.len(), 8); assert_eq!( m["name"].clone().into_str().unwrap(), "Torre di Pisa".to_string() @@ -134,7 +134,7 @@ fn test_map_struct() { let c = make(); let s: Settings = c.try_into().unwrap(); - assert_eq!(s.place.len(), 7); + assert_eq!(s.place.len(), 8); assert_eq!( s.place["name"].clone().into_str().unwrap(), "Torre di Pisa".to_string() -- cgit v1.2.3