use depyler_core::transpile_python_to_rust;
#[test]
fn test_csv_reader() {
let python = r#"
import csv
def read_csv_file(filename: str) -> list:
with open(filename, 'r') as f:
reader = csv.reader(f)
return list(reader)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("csv::Reader") || result.contains("reader"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_reader_with_delimiter() {
let python = r#"
import csv
def read_csv_with_delimiter(filename: str, delim: str) -> list:
with open(filename, 'r') as f:
reader = csv.reader(f, delimiter=delim)
return list(reader)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("delimiter") || result.contains("ReaderBuilder"));
}
#[test]
fn test_csv_writer() {
let python = r#"
import csv
def write_csv_file(filename: str, rows: list) -> None:
with open(filename, 'w') as f:
writer = csv.writer(f)
writer.writerows(rows)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("csv::Writer") || result.contains("writer"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_writer_writerow() {
let python = r#"
import csv
def write_single_row(filename: str, row: list) -> None:
with open(filename, 'w') as f:
writer = csv.writer(f)
writer.writerow(row)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("write_record") || result.contains("serialize"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_writer_writerows() {
let python = r#"
import csv
def write_multiple_rows(filename: str, rows: list) -> None:
with open(filename, 'w') as f:
writer = csv.writer(f)
writer.writerows(rows)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("for") || result.contains("iter"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_dictreader() {
let python = r#"
import csv
def read_csv_as_dict(filename: str) -> list:
with open(filename, 'r') as f:
reader = csv.DictReader(f)
return list(reader)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("DictReader") || result.contains("deserialize"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_dictreader_fieldnames() {
let python = r#"
import csv
def read_with_fieldnames(filename: str, fields: list) -> list:
with open(filename, 'r') as f:
reader = csv.DictReader(f, fieldnames=fields)
return list(reader)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("fieldnames") || result.contains("headers"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_dictwriter() {
let python = r#"
import csv
def write_csv_from_dict(filename: str, fieldnames: list, rows: list) -> None:
with open(filename, 'w') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(rows)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("DictWriter") || result.contains("serialize"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_dictwriter_writeheader() {
let python = r#"
import csv
def write_header(filename: str, fieldnames: list) -> None:
with open(filename, 'w') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("write_record") || result.contains("header"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_excel_dialect() {
let python = r#"
import csv
def read_excel_csv(filename: str) -> list:
with open(filename, 'r') as f:
reader = csv.reader(f, dialect='excel')
return list(reader)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("dialect") || result.contains("excel"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_quote_behavior() {
let python = r#"
import csv
def read_with_quoting(filename: str) -> list:
with open(filename, 'r') as f:
reader = csv.reader(f, quoting=csv.QUOTE_MINIMAL)
return list(reader)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("quote") || result.contains("QuoteStyle"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_escapechar() {
let python = r#"
import csv
def read_with_escape(filename: str) -> list:
with open(filename, 'r') as f:
reader = csv.reader(f, escapechar='\\')
return list(reader)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("escape") || result.contains("escape_char"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_sniffer_sniff() {
let python = r#"
import csv
def detect_dialect(sample: str) -> object:
sniffer = csv.Sniffer()
return sniffer.sniff(sample)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("sniff") || result.contains("detect"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_sniffer_has_header() {
let python = r#"
import csv
def check_has_header(sample: str) -> bool:
sniffer = csv.Sniffer()
return sniffer.has_header(sample)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("has_header") || result.contains("header"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_quote_constants() {
let python = r#"
import csv
def get_quote_all() -> int:
return csv.QUOTE_ALL
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("QUOTE_ALL") || result.contains("QuoteStyle"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_reader_skip_lines() {
let python = r#"
import csv
def read_skip_blank_lines(filename: str) -> list:
with open(filename, 'r') as f:
reader = csv.reader(f, skipinitialspace=True)
return list(reader)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("trim") || result.contains("skip"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_reader_line_num() {
let python = r#"
import csv
def get_line_numbers(filename: str) -> list:
with open(filename, 'r') as f:
reader = csv.reader(f)
return [reader.line_num for row in reader]
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("line_num") || result.contains("position"));
}
#[test]
#[ignore = "DEPYLER-STDLIB-CSV: Not implemented yet - RED phase"]
fn test_csv_error() {
let python = r#"
import csv
def handle_csv_error(filename: str) -> None:
try:
with open(filename, 'r') as f:
reader = csv.reader(f)
list(reader)
except csv.Error as e:
print(f"CSV error: {e}")
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("csv::Error") || result.contains("CsvError"));
}