depyler-core 3.24.0

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

use depyler_core::transpile_python_to_rust;

// DEPYLER-STDLIB-HASHLIB-001: Basic hash algorithms
#[test]
fn test_hashlib_md5() {
    let python = r#"
import hashlib

def hash_md5(data: bytes) -> str:
    return hashlib.md5(data)
"#;

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

    // Should generate md5 hash with hex encoding
    assert!(result.contains("md5") || result.contains("Md5"));
    assert!(result.contains("hex"));
}

#[test]
fn test_hashlib_sha1() {
    let python = r#"
import hashlib

def hash_sha1(data: bytes) -> str:
    return hashlib.sha1(data)
"#;

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

    // Should generate sha1 hash with hex encoding
    assert!(result.contains("sha1") || result.contains("Sha1"));
    assert!(result.contains("hex"));
}

#[test]
fn test_hashlib_sha256() {
    let python = r#"
import hashlib

def hash_sha256(data: bytes) -> str:
    return hashlib.sha256(data)
"#;

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

    // Should generate sha256 hash with hex encoding
    assert!(result.contains("sha256") || result.contains("Sha256"));
    assert!(result.contains("hex"));
}

#[test]
fn test_hashlib_sha512() {
    let python = r#"
import hashlib

def hash_sha512(data: bytes) -> str:
    return hashlib.sha512(data)
"#;

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

    // Should generate sha512 hash with hex encoding
    assert!(result.contains("sha512") || result.contains("Sha512"));
    assert!(result.contains("hex"));
}

// DEPYLER-STDLIB-HASHLIB-002: SHA2 family
#[test]
fn test_hashlib_sha224() {
    let python = r#"
import hashlib

def hash_sha224(data: bytes) -> str:
    return hashlib.sha224(data)
"#;

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

    // Should generate sha224 hash with hex encoding
    assert!(result.contains("sha224") || result.contains("Sha224"));
    assert!(result.contains("hex"));
}

#[test]
fn test_hashlib_sha384() {
    let python = r#"
import hashlib

def hash_sha384(data: bytes) -> str:
    return hashlib.sha384(data)
"#;

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

    // Should generate sha384 hash with hex encoding
    assert!(result.contains("sha384") || result.contains("Sha384"));
    assert!(result.contains("hex"));
}

// DEPYLER-STDLIB-HASHLIB-003: SHA3 family
#[test]
#[ignore = "DEPYLER-STDLIB-HASHLIB: Not implemented yet - RED phase"]
fn test_hashlib_sha3_256() {
    let python = r#"
import hashlib

def hash_sha3_256(data: bytes) -> str:
    return hashlib.sha3_256(data).hexdigest()
"#;

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

    // Should generate sha3_256 hash
    assert!(result.contains("sha3") || result.contains("Sha3"));
}

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

def hash_sha3_512(data: bytes) -> str:
    return hashlib.sha3_512(data).hexdigest()
"#;

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

    // Should generate sha3_512 hash
    assert!(result.contains("sha3") || result.contains("Sha3"));
}

// DEPYLER-STDLIB-HASHLIB-004: BLAKE2 family
#[test]
fn test_hashlib_blake2b() {
    let python = r#"
import hashlib

def hash_blake2b(data: bytes) -> str:
    return hashlib.blake2b(data)
"#;

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

    // Should generate blake2b hash with hex encoding
    assert!(result.contains("blake2") || result.contains("Blake2"));
    assert!(result.contains("hex"));
}

#[test]
fn test_hashlib_blake2s() {
    let python = r#"
import hashlib

def hash_blake2s(data: bytes) -> str:
    return hashlib.blake2s(data)
"#;

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

    // Should generate blake2s hash with hex encoding
    assert!(result.contains("blake2") || result.contains("Blake2"));
    assert!(result.contains("hex"));
}

// DEPYLER-STDLIB-HASHLIB-005: SHAKE algorithms (extendable-output)
#[test]
#[ignore = "DEPYLER-STDLIB-HASHLIB: Not implemented yet - RED phase"]
fn test_hashlib_shake_128() {
    let python = r#"
import hashlib

def hash_shake_128(data: bytes, length: int) -> str:
    return hashlib.shake_128(data).hexdigest(length)
"#;

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

    // Should generate shake_128 hash
    assert!(result.contains("shake") || result.contains("Shake"));
}

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

def hash_shake_256(data: bytes, length: int) -> str:
    return hashlib.shake_256(data).hexdigest(length)
"#;

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

    // Should generate shake_256 hash
    assert!(result.contains("shake") || result.contains("Shake"));
}

// DEPYLER-STDLIB-HASHLIB-006: Hash object methods
#[test]
#[ignore = "DEPYLER-STDLIB-HASHLIB: Not implemented yet - RED phase"]
fn test_hashlib_update() {
    let python = r#"
import hashlib

def incremental_hash(data1: bytes, data2: bytes) -> str:
    h = hashlib.sha256()
    h.update(data1)
    h.update(data2)
    return h.hexdigest()
"#;

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

    // Should generate incremental hashing with update()
    assert!(result.contains("update") || result.contains("Hasher"));
}

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

def hash_digest(data: bytes) -> bytes:
    return hashlib.sha256(data).digest()
"#;

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

    // Should generate digest() for binary output
    assert!(result.contains("digest") || result.contains("finalize"));
}

// DEPYLER-STDLIB-HASHLIB-007: Constructor patterns
#[test]
#[ignore = "DEPYLER-STDLIB-HASHLIB: Not implemented yet - RED phase"]
fn test_hashlib_new() {
    let python = r#"
import hashlib

def hash_with_new(algo: str, data: bytes) -> str:
    return hashlib.new(algo, data).hexdigest()
"#;

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

    // Should generate dynamic algorithm selection
    assert!(result.contains("new") || result.contains("match"));
}

// DEPYLER-STDLIB-HASHLIB-008: Algorithm availability
#[test]
#[ignore = "DEPYLER-STDLIB-HASHLIB: Not implemented yet - RED phase"]
fn test_hashlib_algorithms_available() {
    let python = r#"
import hashlib

def get_algorithms() -> set:
    return hashlib.algorithms_available
"#;

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

    // Should generate list/set of available algorithms
    assert!(result.contains("algorithms") || result.contains("HashSet"));
}

// Total: 17 comprehensive tests for hashlib module
// Coverage: md5, sha1, sha224, sha256, sha384, sha512, sha3_256, sha3_512
//           blake2b, blake2s, shake_128, shake_256
//           Hash methods: update(), digest(), hexdigest()
//           Constructor: new(), algorithms_available