Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test whether unreachable is reachable #183

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,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();
}
}