summaryrefslogtreecommitdiffstats
path: root/tests/get.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/get.rs')
-rw-r--r--tests/get.rs41
1 files changed, 40 insertions, 1 deletions
diff --git a/tests/get.rs b/tests/get.rs
index bf3ba78..a5fea69 100644
--- a/tests/get.rs
+++ b/tests/get.rs
@@ -9,7 +9,7 @@ extern crate serde_derive;
use config::*;
use float_cmp::ApproxEqUlps;
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
#[derive(Debug, Deserialize)]
struct Place {
@@ -226,3 +226,42 @@ fn test_enum() {
assert_eq!(s.diodes["blue"], Diode::Blinking(300, 700));
assert_eq!(s.diodes["white"], Diode::Pattern{name: "christmas".into(), inifinite: true,});
}
+
+#[test]
+fn test_enum_key() {
+ #[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
+ enum Quark {
+ Up,
+ Down,
+ Strange,
+ Charm,
+ Bottom,
+ Top,
+ }
+
+ #[derive(Debug, Deserialize)]
+ struct Settings {
+ proton: HashMap<Quark, usize>,
+ // Just to make sure that set keys work too.
+ quarks: HashSet<Quark>,
+ }
+
+ let c = make();
+ let s: Settings = c.try_into().unwrap();
+
+ assert_eq!(s.proton[&Quark::Up], 2);
+ assert_eq!(s.quarks.len(), 6);
+}
+
+#[test]
+fn test_int_key() {
+ #[derive(Debug, Deserialize, PartialEq)]
+ struct Settings {
+ divisors: HashMap<u32, u32>,
+ }
+
+ let c = make();
+ let s: Settings = c.try_into().unwrap();
+ assert_eq!(s.divisors[&4], 3);
+ assert_eq!(s.divisors.len(), 4);
+}