rust_iso9362 0.1.0

ISO 9362 (Business Identifier Code, also known as the SWIFT/BIC code) defines a standard format for identifying business parties – in particular banks and financial institutions – in financial transactions. This crate parses, validates and decomposes BIC codes into their component parts.
Documentation
#[cfg(feature = "serde")]
mod tests {
    use rust_iso9362::BIC;

    #[test]
    fn test_bic_serialize() {
        let bic = BIC::parse("DEUTDEFF500").unwrap();
        let json = serde_json::to_string(&bic).unwrap();
        assert_eq!(json, "\"DEUTDEFF500\"");

        let bic8 = BIC::parse("DEUTDEFF").unwrap();
        let json = serde_json::to_string(&bic8).unwrap();
        assert_eq!(json, "\"DEUTDEFF\"");
    }

    #[test]
    fn test_bic_deserialize() {
        let bic: BIC = serde_json::from_str("\"DEUTDEFF500\"").unwrap();
        assert_eq!(bic.business_party_prefix(), "DEUT");
        assert_eq!(bic.country_code(), "DE");
        assert_eq!(bic.branch_code(), Some("500"));
    }

    #[test]
    fn test_bic_deserialize_case_insensitive() {
        let bic: BIC = serde_json::from_str("\"deutdeff500\"").unwrap();
        assert_eq!(bic.code(), "DEUTDEFF500");

        let bic: BIC = serde_json::from_str("\"DeUtDeFf\"").unwrap();
        assert_eq!(bic.code(), "DEUTDEFF");
    }

    #[test]
    fn test_bic_roundtrip() {
        let bic = BIC::parse("NEDSZAJJXXX").unwrap();
        let json = serde_json::to_string(&bic).unwrap();
        let back: BIC = serde_json::from_str(&json).unwrap();
        assert_eq!(bic, back);
    }

    #[test]
    fn test_invalid_bic() {
        let result: Result<BIC, _> = serde_json::from_str("\"DEUTDE\"");
        assert!(result.is_err());

        let result: Result<BIC, _> = serde_json::from_str("\"1EUTDEFF\"");
        assert!(result.is_err());

        let result: Result<BIC, _> = serde_json::from_str("\"\"");
        assert!(result.is_err());

        let result: Result<BIC, _> = serde_json::from_str("\"DEUTDEFF5000\"");
        assert!(result.is_err());
    }
}