diff --git a/bacon.toml b/bacon.toml index 42f02c1..21a3578 100644 --- a/bacon.toml +++ b/bacon.toml @@ -25,8 +25,7 @@ command = [ need_stdout = false [jobs.tarpaulin] -command = ["cargo", "tarpaulin", "--color", "always", -"--", "--color", "always"] +command = ["cargo", "tarpaulin", "--color", "always"] need_stdout = true [jobs.clippy-all] diff --git a/src/metar/clouds.rs b/src/metar/clouds.rs index e3fedf4..9e95617 100644 --- a/src/metar/clouds.rs +++ b/src/metar/clouds.rs @@ -107,7 +107,6 @@ impl Display for Clouds { mod tests { use std::str::FromStr; - use anyhow::{Error, Result}; use serde_json::Value; use crate::metar::WxField; @@ -141,6 +140,12 @@ mod tests { assert!(actual.is_none()); } + #[test] + fn test_from_str_err() { + let str = "CLS9999"; + assert!(Clouds::from_str(str).is_err()); + } + #[test] fn test_get_clouds() { let json: Value = Value::from_str( diff --git a/src/metar/units.rs b/src/metar/units.rs index 9128601..001f758 100644 --- a/src/metar/units.rs +++ b/src/metar/units.rs @@ -161,7 +161,7 @@ mod tests { use super::*; #[test] - fn test_units_from_json_invalid() { + fn test_units_from_json_empty() { let json: Value = Value::from_str("{}").unwrap(); let expected: Units = Units { pressure: PressureUnit::Hpa, @@ -173,6 +173,19 @@ mod tests { let actual = Units::from_json(&json); assert_eq!(actual, expected); } + #[test] + fn test_units_from_json_invalid() { + let json: Value = Value::from_str("{\"units\":{\"altimeter\": \"aa\",\"altitude\":\"bb\",\"temperature\":\"cc\",\"wind_speed\": \"dd\", \"visibility\":\"ee\"}}").unwrap(); + let expected: Units = Units { + pressure: PressureUnit::Hpa, + altitude: AltitudeUnit::Ft, + wind_speed: SpeedUnit::Kt, + temperature: TemperatureUnit::C, + distance: DistanceUnit::M, + }; + let actual = Units::from_json(&json); + assert_eq!(actual, expected); + } #[test] fn test_units_from_json_us_units() { diff --git a/src/metar/wxcodes.rs b/src/metar/wxcodes.rs index ba2b5b3..3e7253c 100644 --- a/src/metar/wxcodes.rs +++ b/src/metar/wxcodes.rs @@ -262,7 +262,7 @@ impl FromStr for WxCodeIntensity { "" => Ok(Self::Moderate), "+" => Ok(Self::Heavy), "-" => Ok(Self::Light), - _ => Err(anyhow!("Invalid proximity code {s}.")), + _ => Err(anyhow!("Invalid intensity code {s}.")), } } } @@ -345,7 +345,7 @@ mod tests { use std::str::FromStr; use super::{get_wxcodes_from_json, WxCode, WxCodeIntensity}; - use crate::metar::{WxCodeProximity, WxField}; + use crate::metar::{wxcodes::WxCodeDescription, WxCodeProximity, WxField}; #[test] fn test_get_regex() { @@ -382,9 +382,269 @@ mod tests { } #[test] - fn test_wxcode_from_str() { + fn test_wxcode_from_str_ra() { let expected = WxCode::Ra; let actual = WxCode::from_str("RA").unwrap(); assert_eq!(expected, actual); } + + #[test] + fn test_wxcode_from_str_dz() { + let expected = WxCode::Dz; + let actual = WxCode::from_str("DZ").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_gr() { + let expected = WxCode::Gr; + let actual = WxCode::from_str("GR").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_gs() { + let expected = WxCode::Gs; + let actual = WxCode::from_str("GS").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_ic() { + let expected = WxCode::Ic; + let actual = WxCode::from_str("IC").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_pl() { + let expected = WxCode::Pl; + let actual = WxCode::from_str("PL").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_sg() { + let expected = WxCode::Sg; + let actual = WxCode::from_str("SG").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_sn() { + let expected = WxCode::Sn; + let actual = WxCode::from_str("SN").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_up() { + let expected = WxCode::Up; + let actual = WxCode::from_str("UP").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_br() { + let expected = WxCode::Br; + let actual = WxCode::from_str("BR").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_du() { + let expected = WxCode::Du; + let actual = WxCode::from_str("DU").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_fg() { + let expected = WxCode::Fg; + let actual = WxCode::from_str("FG").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_fu() { + let expected = WxCode::Fu; + let actual = WxCode::from_str("FU").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_hz() { + let expected = WxCode::Hz; + let actual = WxCode::from_str("HZ").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_py() { + let expected = WxCode::Py; + let actual = WxCode::from_str("PY").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_sa() { + let expected = WxCode::Sa; + let actual = WxCode::from_str("SA").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_va() { + let expected = WxCode::Va; + let actual = WxCode::from_str("VA").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_ds() { + let expected = WxCode::Ds; + let actual = WxCode::from_str("DS").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_fc() { + let expected = WxCode::Fc; + let actual = WxCode::from_str("FC").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_po() { + let expected = WxCode::Po; + let actual = WxCode::from_str("PO").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_sq() { + let expected = WxCode::Sq; + let actual = WxCode::from_str("SQ").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_ss() { + let expected = WxCode::Ss; + let actual = WxCode::from_str("SS").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_wxcode_from_str_invalid() { + assert!(WxCode::from_str("INVALID").is_err()); + } + + #[test] + fn test_prox_from_str_dist() { + let expected = WxCodeProximity::Distant; + let actual = WxCodeProximity::from_str("DSNT").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_prox_from_str_vic() { + let expected = WxCodeProximity::Vicinity; + let actual = WxCodeProximity::from_str("VC").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_prox_from_str_invalid() { + assert!(WxCodeProximity::from_str("SOMEWHEREELSE").is_err()); + } + + #[test] + fn test_desc_from_str_ts() { + let expected = WxCodeDescription::Ts; + let actual = WxCodeDescription::from_str("TS").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_desc_from_str_bc() { + let expected = WxCodeDescription::Bc; + let actual = WxCodeDescription::from_str("BC").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_desc_from_str_bl() { + let expected = WxCodeDescription::Bl; + let actual = WxCodeDescription::from_str("BL").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_desc_from_str_dr() { + let expected = WxCodeDescription::Dr; + let actual = WxCodeDescription::from_str("DR").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_desc_from_str_fz() { + let expected = WxCodeDescription::Fz; + let actual = WxCodeDescription::from_str("FZ").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_desc_from_str_mi() { + let expected = WxCodeDescription::Mi; + let actual = WxCodeDescription::from_str("MI").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_desc_from_str_pr() { + let expected = WxCodeDescription::Pr; + let actual = WxCodeDescription::from_str("PR").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_desc_from_str_sh() { + let expected = WxCodeDescription::Sh; + let actual = WxCodeDescription::from_str("SH").unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_desc_from_str_invalid() { + assert!(WxCodeDescription::from_str("SOME").is_err()); + } + + #[test] + fn test_intens_from_str_invalid() { + assert!(WxCodeIntensity::from_str("#").is_err()) + } + + #[test] + fn test_intens_display_light() { + let code = WxCodeIntensity::Light; + let expected = "-"; + let actual = code.to_string(); + assert_eq!(expected, actual); + } + + #[test] + fn test_intens_display_moderate() { + let code = WxCodeIntensity::Moderate; + let expected = ""; + let actual = code.to_string(); + assert_eq!(expected, actual); + } + #[test] + fn test_intens_display_heavy() { + let code = WxCodeIntensity::Heavy; + let expected = "+"; + let actual = code.to_string(); + assert_eq!(expected, actual); + } }