#![allow(missing_docs)]
use rexpect::session::spawn_command;
use std::process::Command;
fn spawn_ruchy_repl() -> rexpect::session::PtySession {
let cmd = Command::new("ruchy");
spawn_command(cmd, Some(10000)).expect("Failed to spawn ruchy REPL")
}
#[test]
fn test_matrix_native_02_01_array_creation() {
let mut repl = spawn_ruchy_repl();
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let data = [[1, 25, 50000], [2, 35, 75000], [3, 45, 100000]]")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("data.len()")
.expect("Failed to send command");
repl.exp_string("3").expect("Array should have 3 rows");
}
#[test]
fn test_matrix_native_02_02_data_filtering() {
let mut repl = spawn_ruchy_repl();
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let data = [[1, 25, 50000], [2, 35, 75000], [3, 45, 100000]]")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let filtered = data.filter(|row| row[1] > 30)")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("filtered.len()")
.expect("Failed to send command");
repl.exp_string("2")
.expect("Filtered data should have 2 rows");
}
#[test]
fn test_matrix_native_02_03_data_mapping() {
let mut repl = spawn_ruchy_repl();
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let data = [[1, 25, 50000], [2, 35, 75000], [3, 45, 100000]]")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let salaries = data.map(|row| row[2])")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("salaries[0]")
.expect("Failed to send command");
repl.exp_string("50000")
.expect("First salary should be 50000");
}
#[test]
fn test_matrix_native_02_04_data_aggregation() {
let mut repl = spawn_ruchy_repl();
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let numbers = [10, 20, 30, 40, 50]")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let sum = numbers.reduce(|acc, x| acc + x, 0)")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("sum").expect("Failed to send command");
repl.exp_string("150").expect("Sum should be 150");
}
#[test]
fn test_matrix_native_02_05_workflow_filter_map_reduce() {
let mut repl = spawn_ruchy_repl();
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("[[1, 25, 50000], [2, 35, 75000], [3, 45, 100000], [4, 32, 80000]].filter(|row| row[1] > 30).map(|row| row[2]).reduce(|acc, x| acc + x, 0)")
.expect("Failed to send command");
repl.exp_string("255000")
.expect("Sum of salaries should be 255000");
}
#[test]
fn test_matrix_native_02_06_nested_data_structures() {
let mut repl = spawn_ruchy_repl();
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line(r#"let row1 = {"id": 1, "name": "Alice", "age": 30}"#)
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("row1.age").expect("Failed to send command");
repl.exp_string("30").expect("Age should be 30");
}
#[test]
fn test_matrix_native_02_07_chained_operations() {
let mut repl = spawn_ruchy_repl();
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line(
"let result = data.filter(|x| x % 2 == 0).map(|x| x * x).reduce(|acc, x| acc + x, 0)",
)
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("result").expect("Failed to send command");
repl.exp_string("220").expect("Result should be 220");
}
#[test]
fn test_matrix_native_02_08_real_world_data_pipeline() {
let mut repl = spawn_ruchy_repl();
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let sales = [[101, 5, 10], [102, 3, 20], [103, 8, 15], [104, 2, 25]]")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let revenues = sales.map(|row| row[1] * row[2])")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("let total_revenue = revenues.reduce(|acc, x| acc + x, 0)")
.expect("Failed to send command");
repl.exp_string("ruchy>")
.expect("Failed to find REPL prompt");
repl.send_line("total_revenue")
.expect("Failed to send command");
repl.exp_string("280").expect("Total revenue should be 280");
}