#[macro_use]
extern crate auto_args;
use auto_args::AutoArgs;
use std::ffi::OsString;
#[derive(PartialEq, Debug, AutoArgs)]
struct Vector3d<T> {
x: T,
y: T,
z: T,
}
#[derive(PartialEq, Debug, AutoArgs)]
#[allow(non_snake_case)]
enum CellDimensions {
CellWidth(Vector3d<f64>),
CellVolume(f64),
}
#[derive(PartialEq, Debug, AutoArgs)]
struct SquareWellParams {
well_width: f64,
_dim: CellDimensions,
}
#[allow(non_snake_case)]
#[derive(PartialEq, Debug, AutoArgs)]
struct SadParams {
min_T: f64,
seed: Option<u64>,
}
#[derive(PartialEq, Debug, AutoArgs)]
enum Params<MP, SP> {
ResumeFrom(String),
_Params { _sys: SP, _mc: MP },
}
#[derive(PartialEq, Debug, AutoArgs)]
struct Simple {
simple: u64,
}
#[derive(PartialEq, Debug, AutoArgs)]
struct Naive {
naive: String,
}
#[test]
fn craziness() {
type P = Params<SadParams, SquareWellParams>;
println!("help: {}", P::help());
println!("\n\n\n\n");
assert!(P::help().contains("--resume-from "));
assert!(P::help().contains("--well-width "));
assert!(P::help().contains("--cell-volume "));
assert!(P::help().contains("--cell-width-x "));
assert!(!P::help().contains("--dim- "));
assert_eq!(
Params::ResumeFrom::<SadParams, SquareWellParams>("hello".to_string()),
P::parse_vec(vec![
OsString::from("--resume-from"),
OsString::from("hello")
])
.unwrap()
);
assert_eq!(
Params::ResumeFrom::<Naive, Simple>("hello".to_string()),
Params::<Naive, Simple>::parse_vec(vec![
OsString::from("--resume-from"),
OsString::from("hello")
])
.unwrap()
);
assert_eq!(
Params::_Params::<Naive, Simple> {
_sys: Simple { simple: 37 },
_mc: Naive {
naive: "goodbye".to_string(),
},
},
Params::<Naive, Simple>::parse_vec(vec![
OsString::from("--simple"),
OsString::from("37"),
OsString::from("--naive"),
OsString::from("goodbye")
])
.unwrap()
);
assert_eq!(
Params::_Params::<SadParams, Simple> {
_sys: Simple { simple: 137 },
_mc: SadParams {
min_T: 0.2,
seed: None,
},
},
Params::<SadParams, Simple>::parse_vec(vec![
OsString::from("--simple"),
OsString::from("137"),
OsString::from("--min-T"),
OsString::from("0.2")
])
.unwrap()
);
assert_eq!(
Params::_Params::<SadParams, SquareWellParams> {
_sys: SquareWellParams {
well_width: 1.3,
_dim: CellDimensions::CellVolume(5.0),
},
_mc: SadParams {
min_T: 0.2,
seed: None,
},
},
P::parse_vec(vec![
OsString::from("--well-width"),
OsString::from("1.3"),
OsString::from("--cell-volume"),
OsString::from("5"),
OsString::from("--min-T"),
OsString::from("0.2")
])
.unwrap()
);
}