depyler-core 3.22.0

Core transpilation engine for the Depyler Python-to-Rust transpiler
Documentation
// Generated by: DEPYLER stdlib validation Phase 1
// Module: textwrap - Python textwrap module validation
// Status: RED phase - Tests written first, implementation pending

use depyler_core::transpile_python_to_rust;

// DEPYLER-STDLIB-TEXTWRAP-001: Text wrapping
#[test]
fn test_wrap() {
    let python = r#"
import textwrap

def wrap_text(text: str, width: int) -> list:
    return textwrap.wrap(text, width)
"#;

    let result = transpile_python_to_rust(python).expect("Transpilation failed");

    // Should wrap text into list of lines
    assert!(result.contains("current_line") || result.contains("split_whitespace"));
}

#[test]
fn test_fill() {
    let python = r#"
import textwrap

def fill_text(text: str, width: int) -> str:
    return textwrap.fill(text, width)
"#;

    let result = transpile_python_to_rust(python).expect("Transpilation failed");

    // Should wrap and join into single string
    assert!(result.contains("join"));
    assert!(result.contains("current_line"));
}

// DEPYLER-STDLIB-TEXTWRAP-002: Indentation
#[test]
fn test_dedent() {
    let python = r#"
import textwrap

def remove_indent(text: str) -> str:
    return textwrap.dedent(text)
"#;

    let result = transpile_python_to_rust(python).expect("Transpilation failed");

    // Should remove common leading whitespace
    assert!(result.contains("min_indent"));
    assert!(result.contains("is_whitespace"));
}

#[test]
fn test_indent() {
    let python = r#"
import textwrap

def add_indent(text: str, prefix: str) -> str:
    return textwrap.indent(text, prefix)
"#;

    let result = transpile_python_to_rust(python).expect("Transpilation failed");

    // Should add prefix to each line
    assert!(result.contains("prefix"));
    assert!(result.contains("lines"));
}

// DEPYLER-STDLIB-TEXTWRAP-003: Text shortening
#[test]
fn test_shorten() {
    let python = r#"
import textwrap

def shorten_text(text: str, width: int) -> str:
    return textwrap.shorten(text, width)
"#;

    let result = transpile_python_to_rust(python).expect("Transpilation failed");

    // Should shorten text with ellipsis placeholder
    assert!(result.contains("placeholder"));
    assert!(result.contains("[...]"));
}

// Total: 5 comprehensive tests for textwrap module
// Coverage: wrap, fill, dedent, indent, shorten
// Text formatting for display and documentation