diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Settings.toml | 3 | ||||
-rw-r--r-- | tests/file_hjson.rs | 2 | ||||
-rw-r--r-- | tests/file_json.rs | 2 | ||||
-rw-r--r-- | tests/file_toml.rs | 12 | ||||
-rw-r--r-- | tests/file_yaml.rs | 2 | ||||
-rw-r--r-- | tests/get.rs | 4 |
6 files changed, 19 insertions, 6 deletions
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_hjson.rs b/tests/file_hjson.rs index f36843a..f8465be 100644 --- a/tests/file_hjson.rs +++ b/tests/file_hjson.rs @@ -43,7 +43,7 @@ fn test_file() { let c = make(); // Deserialize the entire file as single struct - let s: Settings = c.deserialize().unwrap(); + let s: Settings = c.try_into().unwrap(); assert!(s.debug.approx_eq_ulps(&1.0, 2)); assert_eq!(s.production, Some("false".to_string())); diff --git a/tests/file_json.rs b/tests/file_json.rs index 1d35cae..48836d8 100644 --- a/tests/file_json.rs +++ b/tests/file_json.rs @@ -43,7 +43,7 @@ fn test_file() { let c = make(); // Deserialize the entire file as single struct - let s: Settings = c.deserialize().unwrap(); + let s: Settings = c.try_into().unwrap(); assert!(s.debug.approx_eq_ulps(&1.0, 2)); assert_eq!(s.production, Some("false".to_string())); diff --git a/tests/file_toml.rs b/tests/file_toml.rs index f272698..7feb6b5 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<f32>, } +#[derive(Debug, Deserialize, PartialEq)] +struct PlaceNumber(u8); + +#[derive(Debug, Deserialize, PartialEq)] +struct AsciiCode(i8); + #[derive(Debug, Deserialize)] struct Settings { debug: f64, production: Option<String>, + code: AsciiCode, place: Place, #[serde(rename = "arr")] elements: Vec<String>, @@ -43,10 +51,12 @@ fn test_file() { let c = make(); // Deserialize the entire file as single struct - let s: Settings = c.deserialize().unwrap(); + let s: Settings = c.try_into().unwrap(); 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/file_yaml.rs b/tests/file_yaml.rs index 529a8e4..9864133 100644 --- a/tests/file_yaml.rs +++ b/tests/file_yaml.rs @@ -43,7 +43,7 @@ fn test_file() { let c = make(); // Deserialize the entire file as single struct - let s: Settings = c.deserialize().unwrap(); + let s: Settings = c.try_into().unwrap(); assert!(s.debug.approx_eq_ulps(&1.0, 2)); assert_eq!(s.production, Some("false".to_string())); 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<String, Value> = 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() |