summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorbigduu <mugeng.du@qq.com>2023-03-25 23:24:02 +0800
committerbigduu <mugeng.du@qq.com>2023-07-22 00:56:35 +0800
commitb3d851878dd88a62c19cecf3e3bf8a8e2be5309a (patch)
tree6cc041ed5a389f30ec91d20387e05b43aa20816c /tests
parent267afbd4d8ef1f83a3c8af7145ebca51263f4d1b (diff)
Make the parse list key to lowercase when insert the keys
Signed-off-by: bigduu <mugeng.du@qq.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/env.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/env.rs b/tests/env.rs
index a144d08..12a68a9 100644
--- a/tests/env.rs
+++ b/tests/env.rs
@@ -464,6 +464,58 @@ fn test_parse_string_and_list() {
}
#[test]
+fn test_parse_string_and_list_ignore_list_parse_key_case() {
+ // using a struct in an enum here to make serde use `deserialize_any`
+ #[derive(Deserialize, Debug)]
+ #[serde(tag = "tag")]
+ enum TestStringEnum {
+ String(TestString),
+ }
+
+ #[derive(Deserialize, Debug)]
+ struct TestString {
+ string_val: String,
+ string_list: Vec<String>,
+ }
+
+ temp_env::with_vars(
+ vec![
+ ("LIST_STRING_LIST", Some("test,string")),
+ ("LIST_STRING_VAL", Some("test,string")),
+ ],
+ || {
+ let environment = Environment::default()
+ .prefix("LIST")
+ .list_separator(",")
+ .with_list_parse_key("STRING_LIST")
+ .try_parsing(true);
+
+ let config = Config::builder()
+ .set_default("tag", "String")
+ .unwrap()
+ .add_source(environment)
+ .build()
+ .unwrap();
+
+ let config: TestStringEnum = config.try_deserialize().unwrap();
+
+ match config {
+ TestStringEnum::String(TestString {
+ string_val,
+ string_list,
+ }) => {
+ assert_eq!(String::from("test,string"), string_val);
+ assert_eq!(
+ vec![String::from("test"), String::from("string")],
+ string_list
+ );
+ }
+ }
+ },
+ )
+}
+
+#[test]
fn test_parse_nested_kebab() {
use config::Case;