const APPAREL_AND_CLOTHING_ACCESSORIES_PREFIXES: &[&str] = &["4203", "61", "62", "6504", "6505"];
const FOOTWEAR_PREFIXES: &[&str] = &["6401", "6402", "6403", "6404", "6405"];
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AnnexViiHeading {
ApparelAndClothingAccessories,
Footwear,
}
#[must_use]
pub fn annex_vii_heading(commodity_code: &str) -> Option<AnnexViiHeading> {
if APPAREL_AND_CLOTHING_ACCESSORIES_PREFIXES
.iter()
.any(|prefix| commodity_code.starts_with(prefix))
{
Some(AnnexViiHeading::ApparelAndClothingAccessories)
} else if FOOTWEAR_PREFIXES
.iter()
.any(|prefix| commodity_code.starts_with(prefix))
{
Some(AnnexViiHeading::Footwear)
} else {
None
}
}
#[must_use]
pub fn is_within_annex_vii_scope(commodity_code: &str) -> bool {
annex_vii_heading(commodity_code).is_some()
}
#[cfg(test)]
mod tests {
use super::{AnnexViiHeading, annex_vii_heading, is_within_annex_vii_scope};
#[test]
fn apparel_heading_prefixes_are_in_scope() {
assert!(is_within_annex_vii_scope("420321")); assert!(is_within_annex_vii_scope("610910")); assert!(is_within_annex_vii_scope("620342")); assert!(is_within_annex_vii_scope("650400")); assert!(is_within_annex_vii_scope("650500")); }
#[test]
fn footwear_heading_prefixes_are_in_scope() {
assert!(is_within_annex_vii_scope("64011000"));
assert!(is_within_annex_vii_scope("64029900"));
assert!(is_within_annex_vii_scope("64031900"));
assert!(is_within_annex_vii_scope("64041100"));
assert!(is_within_annex_vii_scope("64051000"));
}
#[test]
fn footwear_parts_are_out_of_scope() {
assert!(!is_within_annex_vii_scope("64062000"));
}
#[test]
fn unrelated_chapter_is_out_of_scope() {
assert!(!is_within_annex_vii_scope("851712")); }
#[test]
fn annex_vii_heading_reports_which_heading_matched() {
assert_eq!(
annex_vii_heading("620342"),
Some(AnnexViiHeading::ApparelAndClothingAccessories)
);
assert_eq!(
annex_vii_heading("64011000"),
Some(AnnexViiHeading::Footwear)
);
assert_eq!(annex_vii_heading("851712"), None);
}
}