#![allow(missing_docs)]
use assert_cmd::Command;
use predicates::prelude::*;
fn ruchy_cmd() -> Command {
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
}
#[test]
fn test_parser_008_tuple_three_elements() {
let code = r"
let Color(r, g, b) = red
";
std::fs::write("/tmp/test_parser_008_three.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_008_three.ruchy")
.assert()
.success()
.stdout(predicate::str::contains("✓ Syntax is valid"));
}
#[test]
fn test_parser_008_tuple_two_elements() {
let code = r"
let Point(x, y) = origin
";
std::fs::write("/tmp/test_parser_008_two.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_008_two.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_008_tuple_four_elements() {
let code = r"
let Rgba(r, g, b, a) = color
";
std::fs::write("/tmp/test_parser_008_four.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_008_four.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_008_single_element_still_works() {
let code = r"
let Some(value) = maybe
let Ok(result) = res
let Err(error) = failure
";
std::fs::write("/tmp/test_parser_008_single.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_008_single.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_008_book_example() {
let code = r"
// Creating instances
let origin = Point { x: 0.0, y: 0.0 }
let red = Color(255, 0, 0)
// Field access
let x_coord = origin.x
// Struct update syntax
let point2 = Point { x: 1.0, ..origin }
// Destructuring
let Point { x, y } = origin
let Color(r, g, b) = red
";
std::fs::write("/tmp/test_parser_008_book.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_008_book.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_008_empty_tuple() {
let code = r"
let Unit() = unit_value
";
std::fs::write("/tmp/test_parser_008_empty.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_008_empty.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_008_trailing_comma() {
let code = r"
let Color(r, g, b,) = red
";
std::fs::write("/tmp/test_parser_008_trailing.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_008_trailing.ruchy")
.assert()
.success();
}