import sys
import os
sys.path.append(os.getcwd())

from transpiler.transformer import transpile
from transpiler.flags import RPyFlags

def test_type_inference():
    code = """
def fast_math(n):
    total = 0 # certain number
    for i in range(n): # certain number
        total += i * 2 # inferred number
    return total

x = 10 # certain number
y = "hello" # certain string
z = x + 5 # inferred number
"""
    # Note: Using RPyFlags as defined in flags.py
    flags = RPyFlags(debug_types=True)
    luau = transpile(code, flags)
    
    print("Generated Luau Code:")
    print("-" * 20)
    print(luau)
    print("-" * 20)

    # Verifications
    # The printer emits comments for debug_types
    assert "certain" in luau
    assert "number" in luau
    assert "local x: number = 10" in luau
    assert "local y: string = \"hello\"" in luau
    assert "--!native" in luau
    
    print("S5 Verification PASSED!")

if __name__ == "__main__":
    try:
        test_type_inference()
    except Exception as e:
        print(f"Verification FAILED: {e}")
        import traceback
        traceback.print_exc()
