#![allow(missing_docs)]
use ruchy::frontend::parser::Parser;
#[test]
fn test_parser081_01_array_with_single_variable() {
let code = r"
fun test() {
let x = 42
[x]
}
";
let mut parser = Parser::new(code);
let ast = parser
.parse()
.expect("Parse should succeed with variable in array");
assert!(
matches!(ast.kind, ruchy::frontend::ast::ExprKind::Function { .. }),
"Should parse function with array containing variable"
);
}
#[test]
fn test_parser081_02_array_with_two_variables() {
let code = r#"
fun test() {
let title = "Hello"
let count = 42
[title, count]
}
"#;
let mut parser = Parser::new(code);
let ast = parser
.parse()
.expect("Parse should succeed with two variables in array");
assert!(
matches!(ast.kind, ruchy::frontend::ast::ExprKind::Function { .. }),
"Should parse function with array containing two variables"
);
}
#[test]
fn test_parser081_03_array_with_three_variables() {
let code = r"
fun test() {
let a = 1
let b = 2
let c = 3
[a, b, c]
}
";
let mut parser = Parser::new(code);
let ast = parser
.parse()
.expect("Parse should succeed with three variables in array");
assert!(
matches!(ast.kind, ruchy::frontend::ast::ExprKind::Function { .. }),
"Should parse function with array containing three variables"
);
}
#[test]
fn test_parser081_04_array_mixed_literals_and_variables() {
let code = r"
fun test() {
let x = 42
[1, x, 3]
}
";
let mut parser = Parser::new(code);
let ast = parser
.parse()
.expect("Parse should succeed with mixed array elements");
assert!(
matches!(ast.kind, ruchy::frontend::ast::ExprKind::Function { .. }),
"Should parse function with array mixing literals and variables"
);
}
#[test]
fn test_parser081_05_nested_array_with_variables() {
let code = r"
fun test() {
let x = 1
let y = 2
[[x], [y]]
}
";
let mut parser = Parser::new(code);
let ast = parser
.parse()
.expect("Parse should succeed with nested arrays containing variables");
assert!(
matches!(ast.kind, ruchy::frontend::ast::ExprKind::Function { .. }),
"Should parse function with nested arrays containing variables"
);
}
#[test]
fn test_parser081_06_array_in_function_return() {
let code = r"
fun get_pair(a, b) {
[a, b]
}
";
let mut parser = Parser::new(code);
let ast = parser
.parse()
.expect("Parse should succeed with array of parameters as return value");
assert!(
matches!(ast.kind, ruchy::frontend::ast::ExprKind::Function { .. }),
"Should parse function returning array with parameters"
);
}
#[test]
fn test_parser081_07_array_in_let_binding() {
let code = r"
fun test() {
let x = 10
let y = 20
let pair = [x, y]
pair
}
";
let mut parser = Parser::new(code);
let ast = parser
.parse()
.expect("Parse should succeed with array in let binding");
assert!(
matches!(ast.kind, ruchy::frontend::ast::ExprKind::Function { .. }),
"Should parse function with array assigned to variable"
);
}
#[test]
fn test_parser081_08_array_passed_to_function() {
let code = r"
fun test() {
let x = 1
let y = 2
process([x, y])
}
";
let mut parser = Parser::new(code);
let ast = parser
.parse()
.expect("Parse should succeed with array passed to function");
assert!(
matches!(ast.kind, ruchy::frontend::ast::ExprKind::Function { .. }),
"Should parse function with array as function argument"
);
}
#[test]
fn test_parser081_09_array_with_method_calls() {
let code = r#"
fun test() {
let x = "hello"
[x.len(), x.to_uppercase()]
}
"#;
let mut parser = Parser::new(code);
let ast = parser
.parse()
.expect("Parse should succeed with method calls in array");
assert!(
matches!(ast.kind, ruchy::frontend::ast::ExprKind::Function { .. }),
"Should parse function with array containing method calls"
);
}
#[test]
fn test_parser081_10_array_with_field_access() {
let code = r"
struct Point { x: f64, y: f64 }
fun test() {
let p = Point { x: 10.0, y: 20.0 }
[p.x, p.y]
}
";
let mut parser = Parser::new(code);
let _ast = parser
.parse()
.expect("Parse should succeed with field access in array");
}