#!/usr/bin/env python3
"""
Direct test of the normalization function to see if it's working correctly.
This will help us isolate whether the issue is in normalization or elsewhere.
"""

import sys

sys.path.insert(0, ".")

try:
    import cadar

    # Access the internal normalization directly if possible
    # For now, let's just test a simple case with the full pipeline
    # but with very simple inputs

    test_cases = [
        "aa",
        "ii",
        "uu",
        "oo",
        "aaa",
        "iii",
        "uuu",
        "ooo",
        "لاا",
        "يي",
        "وو",
    ]

    print("Testing normalization impact on simple cases:")
    print("=" * 50)

    for test_input in test_cases:
        print(f"\nInput: '{test_input}'")

        try:
            if all(ord(c) < 128 for c in test_input):  # Latin script
                arabic_result = cadar.bizi2ara(test_input, darija="Ma")
                print(f"  Latin → Arabic: '{test_input}' → '{arabic_result}'")

                # Check if the length was preserved
                if len(test_input) == 2 and len(arabic_result) == 2:
                    print("  ✅ Length preserved (good sign)")
                elif len(test_input) == 2 and len(arabic_result) == 1:
                    print("  ❌ Length reduced (normalization issue?)")
                elif len(test_input) == 3 and len(arabic_result) >= 2:
                    print("  ⚠️  Length changed (might be OK)")

            else:  # Arabic script
                latin_result = cadar.ara2bizi(test_input, darija="Ma")
                print(f"  Arabic → Latin: '{test_input}' → '{latin_result}'")

                # Check if the length was preserved
                if len(test_input) == 2 and len(latin_result) == 2:
                    print("  ✅ Length preserved (good sign)")
                elif len(test_input) == 2 and len(latin_result) == 1:
                    print("  ❌ Length reduced (normalization issue?)")
                elif len(test_input) == 3 and len(latin_result) >= 2:
                    print("  ⚠️  Length changed (might be OK)")

        except Exception as e:
            print(f"  ❌ ERROR: {e}")

except ImportError:
    print("Could not import cadar. Make sure it's built correctly.")
except Exception as e:
    print(f"Error running test: {e}")
