#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
strum_macros::AsRefStr,
strum_macros::EnumString,
strum_macros::FromRepr,
strum_macros::IntoStaticStr,
)]
#[strum(ascii_case_insensitive)]
pub enum SubstanceParam {
#[strum(to_string = "name")]
Name,
#[strum(to_string = "pure", serialize = "is_pure", serialize = "IsPure")]
IsPure,
#[strum(to_string = "aliases")]
Aliases,
#[strum(to_string = "REFPROP_name", serialize = "RefpropName")]
RefpropName,
#[strum(to_string = "CAS", serialize = "CAS_number")]
Cas,
#[allow(clippy::doc_markdown)]
#[strum(to_string = "InChI", serialize = "INCHI_STRING")]
Inchi,
#[allow(clippy::doc_markdown)]
#[strum(to_string = "InChIKey", serialize = "INCHI_Key")]
InchiKey,
#[strum(to_string = "CHEMSPIDER_ID", serialize = "ChemSpiderId")]
ChemSpiderId,
#[strum(to_string = "SMILES")]
Smiles,
#[strum(to_string = "ASHRAE34")]
Ashrae34,
#[strum(to_string = "2DPNG_URL", serialize = "TwoDPngUrl")]
TwoDPngUrl,
#[strum(to_string = "BibTeX-EOS", serialize = "BibTeX_EOS", serialize = "BibtexEos")]
BibtexEos,
#[strum(to_string = "BibTeX-CP0", serialize = "BibTeX_CP0", serialize = "BibtexCp0")]
BibtexCp0,
#[strum(
to_string = "BibTeX-CONDUCTIVITY",
serialize = "BibTeX_CONDUCTIVITY",
serialize = "BibtexConductivity"
)]
BibtexConductivity,
#[strum(
to_string = "BibTeX-MELTING_LINE",
serialize = "BibTeX_MELTING_LINE",
serialize = "BibtexMeltingLine"
)]
BibtexMeltingLine,
#[strum(
to_string = "BibTeX-SURFACE_TENSION",
serialize = "BibTeX_SURFACE_TENSION",
serialize = "BibtexSurfaceTension"
)]
BibtexSurfaceTension,
#[strum(
to_string = "BibTeX-VISCOSITY",
serialize = "BibTeX_VISCOSITY",
serialize = "BibtexViscosity"
)]
BibtexViscosity,
#[strum(to_string = "formula")]
Formula,
#[strum(to_string = "JSON", serialize = "Metadata")]
Metadata,
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
use rstest::*;
use super::{SubstanceParam::*, *};
#[rstest]
#[case(Name, "name")]
#[case(IsPure, "pure")]
#[case(Aliases, "aliases")]
#[case(RefpropName, "REFPROP_name")]
#[case(Cas, "CAS")]
#[case(Inchi, "InChI")]
#[case(InchiKey, "InChIKey")]
#[case(ChemSpiderId, "CHEMSPIDER_ID")]
#[case(Smiles, "SMILES")]
#[case(Ashrae34, "ASHRAE34")]
#[case(TwoDPngUrl, "2DPNG_URL")]
#[case(BibtexEos, "BibTeX-EOS")]
#[case(BibtexCp0, "BibTeX-CP0")]
#[case(BibtexConductivity, "BibTeX-CONDUCTIVITY")]
#[case(BibtexMeltingLine, "BibTeX-MELTING_LINE")]
#[case(BibtexSurfaceTension, "BibTeX-SURFACE_TENSION")]
#[case(BibtexViscosity, "BibTeX-VISCOSITY")]
#[case(Formula, "formula")]
#[case(Metadata, "JSON")]
fn as_str(#[case] sut: SubstanceParam, #[case] expected: &str) {
let str = sut.as_ref();
let static_str: &'static str = sut.into();
assert_eq!(str, expected);
assert_eq!(static_str, expected);
}
#[rstest]
#[case(vec!["name", "Name"], Name)]
#[case(vec!["pure", "is_pure", "IsPure"], IsPure)]
#[case(vec!["aliases", "Aliases"], Aliases)]
#[case(vec!["REFPROP_name", "RefpropName"], RefpropName)]
#[case(vec!["CAS", "CAS_number", "Cas"], Cas)]
#[case(vec!["InChI", "INCHI_STRING", "Inchi"], Inchi)]
#[case(vec!["InChIKey", "INCHI_Key", "InchiKey"], InchiKey)]
#[case(vec!["CHEMSPIDER_ID", "ChemSpiderId"], ChemSpiderId)]
#[case(vec!["SMILES", "smiles"], Smiles)]
#[case(vec!["2DPNG_URL", "TwoDPngUrl"], TwoDPngUrl)]
#[case(vec!["BibTeX-EOS", "BibTeX_EOS", "BibtexEos"], BibtexEos)]
#[case(vec!["BibTeX-CP0", "BibTeX_CP0", "BibtexCp0"], BibtexCp0)]
#[case(
vec!["BibTeX-CONDUCTIVITY", "BibTeX_CONDUCTIVITY", "BibtexConductivity"],
BibtexConductivity
)]
#[case(
vec!["BibTeX-MELTING_LINE", "BibTeX_MELTING_LINE", "BibtexMeltingLine"],
BibtexMeltingLine
)]
#[case(
vec!["BibTeX-SURFACE_TENSION", "BibTeX_SURFACE_TENSION", "BibtexSurfaceTension"],
BibtexSurfaceTension
)]
#[case(vec!["BibTeX-VISCOSITY", "BibTeX_VISCOSITY", "BibtexViscosity"], BibtexViscosity)]
#[case(vec!["formula", "Formula"], Formula)]
#[case(vec!["JSON", "Metadata"], Metadata)]
fn from_valid_str<'a>(#[case] valid: Vec<&'a str>, #[case] expected: SubstanceParam) {
for s in valid {
let res1 = SubstanceParam::from_str(s).unwrap();
let res2 = SubstanceParam::try_from(s).unwrap();
assert_eq!(res1, expected);
assert_eq!(res2, expected);
}
}
#[rstest]
#[case("")]
#[case("Hello, World!")]
fn from_invalid_str(#[case] invalid: &str) {
let res1 = SubstanceParam::from_str(invalid);
let res2 = SubstanceParam::try_from(invalid);
assert!(res1.is_err());
assert!(res2.is_err());
}
}