Skip to content

Commit

Permalink
Test for enum-keys deserialization
Browse files Browse the repository at this point in the history
(Currently failing)

Related to rust-cli#74
  • Loading branch information
vorner committed Aug 5, 2019
1 parent ad29f8f commit 99b06c1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/Settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ code = 53
boolean_s_parse = "fals"

arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
quarks = ["up", "down", "strange", "charm", "bottom", "top"]

[diodes]
green = "off"
Expand Down Expand Up @@ -40,3 +41,7 @@ rating = 4.5

[place.creator]
name = "John Smith"

[proton]
up = 2
down = 1
28 changes: 27 additions & 1 deletion tests/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -225,3 +225,29 @@ 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);
}

0 comments on commit 99b06c1

Please sign in to comment.