summaryrefslogtreecommitdiffstats
path: root/tests/errors.rs
diff options
context:
space:
mode:
authorRyan Leckey <ryan@launchbadge.com>2017-06-03 01:22:38 -0700
committerRyan Leckey <ryan@launchbadge.com>2017-06-03 01:22:38 -0700
commit43c141f87a0167e50802f097cf04896258acb5e6 (patch)
tree799cc797eecf5e699322fbb55debdf75f576a7c0 /tests/errors.rs
parent0a478cf075cc93ede4f631a5be4502e2da2f0cf7 (diff)
Add many more tests
Diffstat (limited to 'tests/errors.rs')
-rw-r--r--tests/errors.rs32
1 files changed, 24 insertions, 8 deletions
diff --git a/tests/errors.rs b/tests/errors.rs
index b69774c..fa3b5ca 100644
--- a/tests/errors.rs
+++ b/tests/errors.rs
@@ -13,19 +13,35 @@ fn make() -> Config {
#[test]
fn test_error_parse() {
let mut c = Config::default();
- c.merge(File::new("tests/Settings.invalid", FileFormat::Toml))
- .unwrap();
+ let res = c.merge(File::new("tests/Settings-invalid", FileFormat::Toml));
+
+ assert!(res.is_err());
+ assert_eq!(res.unwrap_err().to_string(),
+ "invalid number at line 2 in tests/Settings-invalid.toml"
+ .to_string());
+}
+
+#[test]
+fn test_error_type() {
+ let c = make();
+
+ let res = c.get::<bool>("boolean_s_parse");
- assert!(false)
+ assert!(res.is_err());
+ assert_eq!(res.unwrap_err().to_string(),
+ "invalid type: string \"fals\", expected a boolean for key `boolean_s_parse` in tests/Settings.toml"
+ .to_string());
}
#[test]
-fn test_error_type_bool() {
+fn test_error_type_detached() {
let c = make();
- let err = c.get::<bool>("boolean_s_parse");
+ let value = c.get::<Value>("boolean_s_parse").unwrap();
+ let res = value.try_into::<bool>();
- assert!(err.is_err());
- assert_eq!(err.unwrap_err().to_string(),
- "invalid type: string \"fals\", expected a boolean from tests/Settings.toml".to_string());
+ assert!(res.is_err());
+ assert_eq!(res.unwrap_err().to_string(),
+ "invalid type: string \"fals\", expected a boolean"
+ .to_string());
}