depyler-core 3.22.0

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

use depyler_core::transpile_python_to_rust;

// DEPYLER-STDLIB-STRING-001: String constants
#[test]
fn test_string_ascii_letters() {
    let python = r#"
import string

def get_letters() -> str:
    return string.ascii_letters
"#;

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

    // Should generate a string constant with A-Za-z
    assert!(result.contains("ascii_letters") || result.contains("A-Z"));
}

#[test]
fn test_string_ascii_lowercase() {
    let python = r#"
import string

def get_lowercase() -> str:
    return string.ascii_lowercase
"#;

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

    // Should generate "abcdefghijklmnopqrstuvwxyz"
    assert!(result.contains("ascii_lowercase") || result.contains("abcdefghijklmnopqrstuvwxyz"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-STRING: Not implemented yet - RED phase"]
fn test_string_ascii_uppercase() {
    let python = r#"
import string

def get_uppercase() -> str:
    return string.ascii_uppercase
"#;

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

    // Should generate "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    assert!(result.contains("ascii_uppercase") || result.contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
}

#[test]
fn test_string_digits() {
    let python = r#"
import string

def get_digits() -> str:
    return string.digits
"#;

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

    // Should generate "0123456789"
    assert!(result.contains("digits") || result.contains("0123456789"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-STRING: Not implemented yet - RED phase"]
fn test_string_hexdigits() {
    let python = r#"
import string

def get_hexdigits() -> str:
    return string.hexdigits
"#;

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

    // Should generate "0123456789abcdefABCDEF"
    assert!(result.contains("hexdigits") || result.contains("0123456789abcdef"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-STRING: Not implemented yet - RED phase"]
fn test_string_octdigits() {
    let python = r#"
import string

def get_octdigits() -> str:
    return string.octdigits
"#;

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

    // Should generate "01234567"
    assert!(result.contains("octdigits") || result.contains("01234567"));
}

#[test]
fn test_string_punctuation() {
    let python = r#"
import string

def get_punctuation() -> str:
    return string.punctuation
"#;

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

    // Should generate punctuation characters
    assert!(result.contains("punctuation") || result.contains("!"));
}

#[test]
fn test_string_whitespace() {
    let python = r#"
import string

def get_whitespace() -> str:
    return string.whitespace
"#;

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

    // Should generate whitespace characters
    assert!(result.contains("whitespace") || result.contains("\\t\\n"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-STRING: Not implemented yet - RED phase"]
fn test_string_printable() {
    let python = r#"
import string

def get_printable() -> str:
    return string.printable
"#;

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

    // Should generate all printable ASCII characters
    assert!(result.contains("printable"));
}

// DEPYLER-STDLIB-STRING-002: String formatting (Template class)
#[test]
#[ignore = "DEPYLER-STDLIB-STRING: Not implemented yet - RED phase"]
fn test_string_template_substitute() {
    let python = r#"
import string

def format_template(name: str) -> str:
    template = string.Template('Hello $name!')
    return template.substitute(name=name)
"#;

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

    // Should generate string substitution/formatting
    assert!(result.contains("format") || result.contains("replace"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-STRING: Not implemented yet - RED phase"]
fn test_string_template_safe_substitute() {
    let python = r#"
import string

def safe_format(template_str: str, data: dict) -> str:
    template = string.Template(template_str)
    return template.safe_substitute(data)
"#;

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

    // Should generate safe string substitution
    assert!(result.contains("substitute") || result.contains("replace"));
}

// DEPYLER-STDLIB-STRING-003: String utilities
#[test]
fn test_string_capwords() {
    let python = r#"
import string

def capitalize_words(text: str) -> str:
    return string.capwords(text)
"#;

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

    // Should generate word capitalization logic
    assert!(result.contains("split") || result.contains("capitalize"));
}

// DEPYLER-STDLIB-STRING-004: Formatter class
#[test]
#[ignore = "DEPYLER-STDLIB-STRING: Not implemented yet - RED phase"]
fn test_string_formatter_format() {
    let python = r#"
import string

def format_string(fmt: str, value: int) -> str:
    formatter = string.Formatter()
    return formatter.format(fmt, value)
"#;

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

    // Should generate format! macro or string formatting
    assert!(result.contains("format"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-STRING: Not implemented yet - RED phase"]
fn test_string_formatter_vformat() {
    let python = r#"
import string

def vformat_string(fmt: str, args: list, kwargs: dict) -> str:
    formatter = string.Formatter()
    return formatter.vformat(fmt, args, kwargs)
"#;

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

    // Should generate format! macro with variable args
    assert!(result.contains("format"));
}

// DEPYLER-STDLIB-STRING-005: Character classification helpers
#[test]
#[ignore = "DEPYLER-STDLIB-STRING: Not implemented yet - RED phase"]
fn test_check_if_digit() {
    let python = r#"
import string

def is_digit_char(c: str) -> bool:
    return c in string.digits
"#;

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

    // Should generate digit checking logic
    assert!(result.contains("digits") || result.contains("is_digit"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-STRING: Not implemented yet - RED phase"]
fn test_check_if_letter() {
    let python = r#"
import string

def is_letter(c: str) -> bool:
    return c in string.ascii_letters
"#;

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

    // Should generate letter checking logic
    assert!(result.contains("ascii_letters") || result.contains("is_alphabetic"));
}

// Total: 16 comprehensive tests for string module
// Coverage: Constants (9), Template (2), utilities (capwords), Formatter (2), classification (2)