#[derive(Debug, PartialEq)]
pub struct Site {
pub id: String,
pub name: Option<String>,
pub notes: Option<String>,
pub state: Option<StateProv>,
pub auto_download: bool,
}
impl Site {
pub fn incomplete(&self) -> bool {
self.name.is_none() || self.state.is_none()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumString, AsStaticStr, EnumIter)]
#[allow(missing_docs)]
pub enum StateProv {
AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA, WV, WI, WY, AS, DC, FM, MH, MP, PW, PR, VI, }
#[cfg(test)]
mod unit {
use super::*;
use std::str::FromStr;
use strum::{AsStaticRef, IntoEnumIterator};
#[test]
fn test_site_incomplete() {
let complete_site = Site {
id: "kxly".to_owned(),
name: Some("tv station".to_owned()),
state: Some(StateProv::VI),
notes: Some("".to_owned()),
auto_download: false,
};
let incomplete_site = Site {
id: "kxly".to_owned(),
name: Some("tv station".to_owned()),
state: None,
notes: None,
auto_download: true,
};
assert!(!complete_site.incomplete());
assert!(incomplete_site.incomplete());
}
#[test]
fn test_to_string_for_state_prov() {
assert_eq!(StateProv::AL.as_static(), "AL");
}
#[test]
fn test_from_string_for_state_prov() {
assert_eq!(StateProv::from_str("AL").unwrap(), StateProv::AL);
}
#[test]
fn round_trip_strings_for_state_prov() {
for state_prov in StateProv::iter() {
assert_eq!(
StateProv::from_str(state_prov.as_static()).unwrap(),
state_prov
);
}
}
}