1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Generated by: DEPYLER stdlib validation Phase 1
// Module: str - Additional string methods
// Status: GREEN phase - Tests enabled
use depyler_core::transpile_python_to_rust;
// Note: count() and find() were already implemented
// This commit adds 3 NEW methods: index, rfind, rindex
// DEPYLER-STDLIB-STR-ADDITIONAL-001: Index with error on not found
#[test]
fn test_str_index() {
let python = r#"
def get_index(text: str, sub: str) -> int:
return text.index(sub)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
// Should find index or panic
assert!(result.contains("find") && result.contains("expect"));
}
// DEPYLER-STDLIB-STR-ADDITIONAL-002: Reverse find
#[test]
fn test_str_rfind() {
let python = r#"
def find_last(text: str, sub: str) -> int:
return text.rfind(sub)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
// Should find last occurrence
assert!(result.contains("rfind"));
}
// DEPYLER-STDLIB-STR-ADDITIONAL-003: Reverse index
#[test]
fn test_str_rindex() {
let python = r#"
def get_last_index(text: str, sub: str) -> int:
return text.rindex(sub)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
// Should find last index or panic
assert!(result.contains("rfind") && result.contains("expect"));
}
// Total: 3 NEW str methods (count, find already existed)
// Coverage: index(), rfind(), rindex()