summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2022-08-02 08:44:21 +0200
committerMatthias Beyer <mail@beyermatthias.de>2022-08-02 09:29:05 +0200
commitb7688b7f5792e784a4b0e5175141aa0c317e2e10 (patch)
tree46f4a498257dcaf3bef418bdfd894247d7311bd3
parentab556a90de314ed8fa91840b3159ec124c0a2b35 (diff)
Duplicate test for type conversion with unsigned int
This patch duplicates the test that was done with indexmap here with the normal HashMap from std. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--tests/unsigned_int_hm.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/unsigned_int_hm.rs b/tests/unsigned_int_hm.rs
new file mode 100644
index 0000000..ab2a60c
--- /dev/null
+++ b/tests/unsigned_int_hm.rs
@@ -0,0 +1,46 @@
+#![cfg(not(feature = "preserve_order"))]
+
+#[derive(serde::Deserialize, Eq, PartialEq, Debug)]
+struct Container<T> {
+ inner: T,
+}
+
+#[derive(serde::Deserialize, Eq, PartialEq, Debug)]
+struct Unsigned {
+ unsigned: u16,
+}
+
+impl Default for Unsigned {
+ fn default() -> Self {
+ Self { unsigned: 128 }
+ }
+}
+
+impl From<Unsigned> for config::ValueKind {
+ fn from(unsigned: Unsigned) -> Self {
+ let mut properties = std::collections::HashMap::new();
+ properties.insert(
+ "unsigned".to_string(),
+ config::Value::from(unsigned.unsigned),
+ );
+
+ Self::Table(properties)
+ }
+}
+
+#[test]
+fn test_deser_unsigned_int_hm() {
+ let container = Container {
+ inner: Unsigned::default(),
+ };
+
+ let built = config::Config::builder()
+ .set_default("inner", Unsigned::default())
+ .unwrap()
+ .build()
+ .unwrap()
+ .try_deserialize::<Container<Unsigned>>()
+ .unwrap();
+
+ assert_eq!(container, built);
+}