Skip to content

Commit

Permalink
Add test whether unreachable is reachable
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Beyer <[email protected]>
  • Loading branch information
matthiasbeyer committed Mar 26, 2021
1 parent 20d3772 commit de7cf3a
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,58 @@ impl<'de> de::Deserializer<'de> for Config {
identifier ignored_any unit_struct tuple_struct tuple
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::Config;
use crate::File;
use crate::FileFormat;

#[derive(Deserialize)]
struct CFG {
e: EnumConfig,
}

#[derive(Deserialize)]
enum EnumConfig {
Foo,
Bar { filename: std::path::PathBuf },
}

#[test]
fn test_unreachable_reachable_not_panicing_1() {
let working_config = r#"
e.bar.filename = "blah"
"#;

let mut c = Config::default();
c.merge(File::from_str(working_config, FileFormat::Toml))
.unwrap();
let c: CFG = c.try_into().unwrap();
}
#[test]
fn test_unreachable_reachable_not_panicing_2() {
let working_config = r#"
e = "foo"
"#;

let mut c = Config::default();
c.merge(File::from_str(working_config, FileFormat::Toml))
.unwrap();
let c: CFG = c.try_into().unwrap();
}

#[test]
#[should_panic]
fn test_unreachable_reachable_panicing() {
let panicing_config = r#"
e = "bar"
"#;

let mut c = Config::default();
c.merge(File::from_str(panicing_config, FileFormat::Toml))
.unwrap();
let c: CFG = c.try_into().unwrap();
}
}

0 comments on commit de7cf3a

Please sign in to comment.