#[cfg(test)]
mod tests {
    use super::*;
    use crate::stages::icr::{ICRMetadata, ICRSegment};
    use crate::types::Dialect;

    #[test]
    fn test_digit_reverse_mappings() {
        let generator = ScriptGenerator::new();

        // Test reverse mapping: "ʾ" should map to "2" (hamza)
        let icr_hamza = ICR {
            segments: vec![
                ICRSegment {
                    canonical: "M".to_string(),
                    original: "م".to_string(),
                    segment_type: SegmentType::Consonant,
                    confidence: 1.0,
                    word_context: None,
                },
                ICRSegment {
                    canonical: "R".to_string(),
                    original: "ر".to_string(),
                    segment_type: SegmentType::Consonant,
                    confidence: 1.0,
                    word_context: None,
                },
                ICRSegment {
                    canonical: "ʾ".to_string(), // hamza from digit 2
                    original: "ء".to_string(),
                    segment_type: SegmentType::Consonant,
                    confidence: 1.0,
                    word_context: None,
                },
                ICRSegment {
                    canonical: "A".to_string(),
                    original: "ا".to_string(),
                    segment_type: SegmentType::Vowel,
                    confidence: 1.0,
                    word_context: None,
                },
            ],
            dialect: Dialect::Moroccan,
            metadata: ICRMetadata {
                source_script: Script::Arabic,
                total_segments: 4,
                confidence_avg: 1.0,
            },
        };

        let result = generator.generate(&icr_hamza, Script::Latin).unwrap();
        assert_eq!(result, "mr2a"); // Should map back to "mr2a"

        // Test reverse mapping: "Ġ" should map to "8" (ghayn)
        let icr_ghayn = ICR {
            segments: vec![
                ICRSegment {
                    canonical: "T".to_string(),
                    original: "ت".to_string(),
                    segment_type: SegmentType::Consonant,
                    confidence: 1.0,
                    word_context: None,
                },
                ICRSegment {
                    canonical: "8".to_string(), // This should stay as 8 (Number type)
                    original: "8".to_string(),
                    segment_type: SegmentType::Number,
                    confidence: 1.0,
                    word_context: None,
                },
                ICRSegment {
                    canonical: "Ġ".to_string(), // ghayn from digit 8
                    original: "غ".to_string(),
                    segment_type: SegmentType::Consonant,
                    confidence: 1.0,
                    word_context: None,
                },
                ICRSegment {
                    canonical: "L".to_string(),
                    original: "ل".to_string(),
                    segment_type: SegmentType::Consonant,
                    confidence: 1.0,
                    word_context: None,
                },
                ICRSegment {
                    canonical: "A".to_string(),
                    original: "ا".to_string(),
                    segment_type: SegmentType::Vowel,
                    confidence: 1.0,
                    word_context: None,
                },
            ],
            dialect: Dialect::Moroccan,
            metadata: ICRMetadata {
                source_script: Script::Arabic,
                total_segments: 5,
                confidence_avg: 1.0,
            },
        };

        let result_ghayn = generator.generate(&icr_ghayn, Script::Latin).unwrap();
        assert_eq!(result_ghayn, "t8Ġla"); // Should map to "t8Ġla" (8 as number, Ġ as consonant)
    }
}
