pub struct ErrorCodes;
impl ErrorCodes {
pub const MISSING_MANDATORY_SEGMENT: &'static str = "STR001";
pub const MAX_REPETITIONS_EXCEEDED: &'static str = "STR002";
pub const UNEXPECTED_SEGMENT: &'static str = "STR003";
pub const WRONG_SEGMENT_ORDER: &'static str = "STR004";
pub const MISSING_MANDATORY_GROUP: &'static str = "STR005";
pub const GROUP_MAX_REP_EXCEEDED: &'static str = "STR006";
pub const UNT_SEGMENT_COUNT_MISMATCH: &'static str = "STR007";
pub const SKIPPED_UNKNOWN_SEGMENT: &'static str = "STR008";
pub const VALUE_TOO_LONG: &'static str = "FMT001";
pub const INVALID_NUMERIC_FORMAT: &'static str = "FMT002";
pub const INVALID_ALPHANUMERIC_FORMAT: &'static str = "FMT003";
pub const INVALID_DATE_FORMAT: &'static str = "FMT004";
pub const VALUE_TOO_SHORT: &'static str = "FMT005";
pub const REQUIRED_ELEMENT_EMPTY: &'static str = "FMT006";
pub const INVALID_CODE_VALUE: &'static str = "COD001";
pub const CODE_NOT_ALLOWED_FOR_PID: &'static str = "COD002";
pub const MISSING_REQUIRED_FIELD: &'static str = "AHB001";
pub const FIELD_NOT_ALLOWED_FOR_PID: &'static str = "AHB002";
pub const CONDITIONAL_RULE_VIOLATION: &'static str = "AHB003";
pub const UNKNOWN_PRUEFIDENTIFIKATOR: &'static str = "AHB004";
pub const CONDITION_UNKNOWN: &'static str = "AHB005";
pub const PACKAGE_CARDINALITY_VIOLATION: &'static str = "AHB006";
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_code_prefixes() {
assert!(ErrorCodes::MISSING_MANDATORY_SEGMENT.starts_with("STR"));
assert!(ErrorCodes::VALUE_TOO_LONG.starts_with("FMT"));
assert!(ErrorCodes::INVALID_CODE_VALUE.starts_with("COD"));
assert!(ErrorCodes::MISSING_REQUIRED_FIELD.starts_with("AHB"));
}
#[test]
fn test_all_codes_are_unique() {
let codes = [
ErrorCodes::MISSING_MANDATORY_SEGMENT,
ErrorCodes::MAX_REPETITIONS_EXCEEDED,
ErrorCodes::UNEXPECTED_SEGMENT,
ErrorCodes::WRONG_SEGMENT_ORDER,
ErrorCodes::MISSING_MANDATORY_GROUP,
ErrorCodes::GROUP_MAX_REP_EXCEEDED,
ErrorCodes::UNT_SEGMENT_COUNT_MISMATCH,
ErrorCodes::SKIPPED_UNKNOWN_SEGMENT,
ErrorCodes::VALUE_TOO_LONG,
ErrorCodes::INVALID_NUMERIC_FORMAT,
ErrorCodes::INVALID_ALPHANUMERIC_FORMAT,
ErrorCodes::INVALID_DATE_FORMAT,
ErrorCodes::VALUE_TOO_SHORT,
ErrorCodes::REQUIRED_ELEMENT_EMPTY,
ErrorCodes::INVALID_CODE_VALUE,
ErrorCodes::CODE_NOT_ALLOWED_FOR_PID,
ErrorCodes::MISSING_REQUIRED_FIELD,
ErrorCodes::FIELD_NOT_ALLOWED_FOR_PID,
ErrorCodes::CONDITIONAL_RULE_VIOLATION,
ErrorCodes::UNKNOWN_PRUEFIDENTIFIKATOR,
ErrorCodes::CONDITION_UNKNOWN,
ErrorCodes::PACKAGE_CARDINALITY_VIOLATION,
];
let unique: std::collections::HashSet<&str> = codes.iter().copied().collect();
assert_eq!(codes.len(), unique.len(), "Duplicate error codes found");
}
}