From 7a0926770b43893a59f016a6ca2bb5a183d70971 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 19 Jan 2023 09:14:58 +0100 Subject: Add test with rust_decimal To test issue #414 Signed-off-by: Matthias Beyer --- Cargo.toml | 1 + tests/yaml-decimal.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/yaml-decimal.rs 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, +} + +#[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))); +} -- cgit v1.2.3