summaryrefslogtreecommitdiffstats
path: root/tests/file_ini.rs
diff options
context:
space:
mode:
authorsaber.wu <saber.wu@trantect.com>2018-06-14 17:09:43 +0800
committersaber.wu <saber.wu@trantect.com>2018-06-15 11:13:53 +0800
commitba6014543dfb4040921bb4809c6b293cfdf33c84 (patch)
tree523708c74eb31e5c861c7e474f092fafbd416879 /tests/file_ini.rs
parente8fa9fee96185ddd18ebcef8a925c75459111edb (diff)
support ini
Diffstat (limited to 'tests/file_ini.rs')
-rw-r--r--tests/file_ini.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/file_ini.rs b/tests/file_ini.rs
new file mode 100644
index 0000000..4c0030a
--- /dev/null
+++ b/tests/file_ini.rs
@@ -0,0 +1,60 @@
+extern crate config;
+extern crate serde;
+extern crate float_cmp;
+
+#[macro_use]
+extern crate serde_derive;
+
+use config::*;
+
+#[derive(Debug, Deserialize, PartialEq)]
+struct Place {
+ name: String,
+ longitude: f64,
+ latitude: f64,
+ favorite: bool,
+ reviews: u64,
+ rating: Option<f32>,
+}
+
+#[derive(Debug, Deserialize, PartialEq)]
+struct Settings {
+ debug: f64,
+ place: Place,
+}
+
+fn make() -> Config {
+ let mut c = Config::default();
+ c.merge(File::new("tests/Settings", FileFormat::Ini))
+ .unwrap();
+ c
+}
+
+#[test]
+fn test_file() {
+ let c = make();
+ let s: Settings = c.try_into().unwrap();
+ assert_eq!(s, Settings {
+ debug: 1.0,
+ place: Place {
+ name: String::from("Torre di Pisa"),
+ longitude: 43.7224985,
+ latitude: 10.3970522,
+ favorite: false,
+ reviews: 3866,
+ rating: Some(4.5),
+ },
+ });
+}
+
+#[test]
+fn test_error_parse() {
+ let mut c = Config::default();
+ let res = c.merge(File::new("tests/Settings-invalid", FileFormat::Ini));
+
+ assert!(res.is_err());
+ assert_eq!(
+ res.unwrap_err().to_string(),
+ r#"2:0 Expecting "[Some('='), Some(':')]" but found EOF. in tests/Settings-invalid.ini"#
+ );
+}