#![allow(missing_docs)]
use assert_cmd::Command;
use std::fs;
use tempfile::TempDir;
fn ruchy_cmd() -> Command {
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
}
fn temp_dir() -> TempDir {
TempDir::new().expect("Failed to create temp directory")
}
#[test]
fn test_stdlib_defect_002_green_split_with_len() {
let temp = temp_dir();
let source = temp.path().join("test.ruchy");
let code = r#"
fun main() {
let text = "a,b,c";
let parts = text.split(",");
println(parts.len());
}
"#;
fs::write(&source, code).expect("Failed to write test file");
ruchy_cmd().arg("run").arg(&source).assert().success();
}
#[test]
fn test_stdlib_defect_002_green_split_with_iteration() {
let temp = temp_dir();
let source = temp.path().join("test.ruchy");
let code = r#"
fun main() {
let text = "hello,world,test";
let parts = text.split(",");
for part in parts {
println(part);
}
}
"#;
fs::write(&source, code).expect("Failed to write test file");
ruchy_cmd().arg("run").arg(&source).assert().success();
}
#[test]
fn test_stdlib_defect_002_green_split_with_index() {
let temp = temp_dir();
let source = temp.path().join("test.ruchy");
let code = r#"
fun main() {
let text = "first,second,third";
let parts = text.split(",");
println(parts[0]);
println(parts[1]);
}
"#;
fs::write(&source, code).expect("Failed to write test file");
ruchy_cmd().arg("run").arg(&source).assert().success();
}
#[test]
fn test_stdlib_defect_002_green_split_compile() {
let temp = temp_dir();
let source = temp.path().join("test.ruchy");
let code = r#"
fun main() {
let csv = "name,age,city";
let fields = csv.split(",");
println("Fields:");
println(fields.len());
}
"#;
fs::write(&source, code).expect("Failed to write test file");
ruchy_cmd()
.arg("compile")
.arg(&source)
.arg("-o")
.arg(temp.path().join("test_binary"))
.assert()
.success();
}
#[test]
fn test_stdlib_defect_002_green_split_empty() {
let temp = temp_dir();
let source = temp.path().join("test.ruchy");
let code = r#"
fun main() {
let text = "";
let parts = text.split(",");
println(parts.len());
}
"#;
fs::write(&source, code).expect("Failed to write test file");
ruchy_cmd().arg("run").arg(&source).assert().success();
}
#[test]
fn test_stdlib_defect_002_green_split_various_delims() {
let temp = temp_dir();
let source = temp.path().join("test.ruchy");
let code = r#"
fun main() {
let text1 = "a;b;c";
let parts1 = text1.split(";");
println(parts1.len());
let text2 = "one two three";
let parts2 = text2.split(" ");
println(parts2.len());
}
"#;
fs::write(&source, code).expect("Failed to write test file");
ruchy_cmd().arg("run").arg(&source).assert().success();
}
#[test]
fn test_stdlib_defect_002_baseline_builtins() {
let temp = temp_dir();
let source = temp.path().join("test.ruchy");
let code = r#"
fun main() {
let text = "hello";
let upper = text.to_upper();
println(upper);
}
"#;
fs::write(&source, code).expect("Failed to write test file");
ruchy_cmd().arg("run").arg(&source).assert().success();
}
#[test]
fn test_stdlib_defect_002_summary() {
println!("STDLIB-DEFECT-002: .split() Returns Internal Rust Type");
println!("- .split() returns std::str::Split iterator");
println!("- Should return Vec<String>");
println!("- Error: cannot call .len() on iterator");
println!();
println!("Root Cause:");
println!("- Transpiler emits raw .split() call");
println!("- Doesn't collect() iterator into Vec");
println!();
println!("Solution Needed:");
println!("- Change transpiler to emit .split().collect::<Vec<_>>()");
println!("- Similar to how .substring() collects into String");
}