Skip to main content

automapper_validation/validator/
level.rs

1//! Validation level configuration.
2
3use serde::{Deserialize, Serialize};
4
5/// Level of validation strictness.
6///
7/// Controls which checks are performed during validation.
8#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9pub enum ValidationLevel {
10    /// Validate only EDIFACT structure: segment presence, ordering, and
11    /// repetition counts against the MIG schema.
12    #[serde(alias = "structure")]
13    Structure,
14
15    /// Validate structure plus AHB condition expressions for the detected
16    /// Pruefidentifikator. Requires a registered `ConditionEvaluator`.
17    #[serde(alias = "conditions")]
18    Conditions,
19
20    /// Full validation: structure, conditions, format checks, and code
21    /// value restrictions. The most thorough level.
22    #[default]
23    #[serde(alias = "full")]
24    Full,
25}
26
27impl std::fmt::Display for ValidationLevel {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        match self {
30            ValidationLevel::Structure => write!(f, "Structure"),
31            ValidationLevel::Conditions => write!(f, "Conditions"),
32            ValidationLevel::Full => write!(f, "Full"),
33        }
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn test_default_is_full() {
43        assert_eq!(ValidationLevel::default(), ValidationLevel::Full);
44    }
45
46    #[test]
47    fn test_display() {
48        assert_eq!(format!("{}", ValidationLevel::Structure), "Structure");
49        assert_eq!(format!("{}", ValidationLevel::Conditions), "Conditions");
50        assert_eq!(format!("{}", ValidationLevel::Full), "Full");
51    }
52
53    #[test]
54    fn test_serialization_roundtrip() {
55        let level = ValidationLevel::Conditions;
56        let json = serde_json::to_string(&level).unwrap();
57        let deserialized: ValidationLevel = serde_json::from_str(&json).unwrap();
58        assert_eq!(level, deserialized);
59    }
60}