summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2023-01-19 09:14:58 +0100
committerMatthias Beyer <mail@beyermatthias.de>2023-01-19 09:14:59 +0100
commit7a0926770b43893a59f016a6ca2bb5a183d70971 (patch)
tree708e16c3b456b296f512560454e00c0f6da2ddc4
parent9a1c74ddf7763566b71049877c047a6545aa59c6 (diff)
Add test with rust_decimaltest-decimal
To test issue #414 Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--Cargo.toml1
-rw-r--r--tests/yaml-decimal.rs28
2 files changed, 29 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 9d86fd3..2c4c9f1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -55,3 +55,4 @@ lazy_static = "1"
notify = "^5.0.0"
temp-env = "0.3.0"
log = { version = "0.4", features = ["serde"] }
+rust_decimal = "1.27.0"
diff --git a/tests/yaml-decimal.rs b/tests/yaml-decimal.rs
new file mode 100644
index 0000000..5a43a8d
--- /dev/null
+++ b/tests/yaml-decimal.rs
@@ -0,0 +1,28 @@
+#![cfg(feature = "yaml")]
+
+use rust_decimal::Decimal;
+use serde::Deserialize;
+use config::{File, FileFormat};
+
+const YAML: &str = r"
+foo: 100.0
+bar: 200.0
+";
+
+#[derive(Debug, Deserialize)]
+pub struct Config {
+ pub foo: Decimal,
+ pub bar: Option<Decimal>,
+}
+
+#[test]
+fn test_yaml_decimal() {
+ let c: Config = config::Config::builder()
+ .add_source(File::from_str(YAML, FileFormat::Yaml))
+ .build()
+ .unwrap()
+ .try_deserialize()
+ .expect("Deserialization failed");
+ assert_eq!(c.foo, Decimal::from(100));
+ assert_eq!(c.bar, Some(Decimal::from(200)));
+}