Skip to content

Commit

Permalink
Merge pull request #359 from matthiasbeyer/add-test-deser-unsigned-ints
Browse files Browse the repository at this point in the history
Add test to deserialize unsigned int
  • Loading branch information
matthiasbeyer committed Jul 26, 2022
2 parents 84efcc8 + 6ea01f1 commit af537b7
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/unsigned_int.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#![cfg(feature = "preserve_order")]

extern crate indexmap;

#[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 = indexmap::IndexMap::new();
properties.insert(
"unsigned".to_string(),
config::Value::from(unsigned.unsigned),
);

Self::Table(properties)
}
}

#[test]
fn test_deser_unsigned_int() {
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);
}

0 comments on commit af537b7

Please sign in to comment.