#![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_009_basic_struct_variant() {
let code = r"
enum Message {
Quit,
Move { x: i32, y: i32 },
Write(String),
}
";
std::fs::write("/tmp/test_parser_009_basic.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_009_basic.ruchy")
.assert()
.success()
.stdout(predicate::str::contains("✓ Syntax is valid"));
}
#[test]
fn test_parser_009_struct_variant_only() {
let code = r"
enum Position {
Point { x: i32, y: i32, z: i32 },
}
";
std::fs::write("/tmp/test_parser_009_struct_only.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_009_struct_only.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_009_multiple_struct_variants() {
let code = r"
enum Shape {
Circle { radius: f64 },
Rectangle { width: f64, height: f64 },
Triangle { base: f64, height: f64, angle: f64 },
}
";
std::fs::write("/tmp/test_parser_009_multiple.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_009_multiple.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_009_mixed_variants() {
let code = r"
enum Event {
Quit,
KeyPress(char),
MouseMove { x: i32, y: i32 },
Click { x: i32, y: i32, button: String },
}
";
std::fs::write("/tmp/test_parser_009_mixed.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_009_mixed.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_009_generic_struct_variant() {
let code = r"
enum Result<T, E> {
Ok(T),
Err(E),
}
";
std::fs::write("/tmp/test_parser_009_generic.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_009_generic.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_009_trailing_comma() {
let code = r"
enum Message {
Move { x: i32, y: i32, },
}
";
std::fs::write("/tmp/test_parser_009_trailing.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_009_trailing.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_009_empty_struct_variant() {
let code = r"
enum Empty {
Unit {},
}
";
std::fs::write("/tmp/test_parser_009_empty.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_009_empty.ruchy")
.assert()
.success();
}
#[test]
fn test_parser_009_book_example() {
let code = r"
// Enum definition
enum Message {
Quit,
Move { x: i32, y: i32 },
Write(String),
}
";
std::fs::write("/tmp/test_parser_009_book.ruchy", code).unwrap();
ruchy_cmd()
.arg("check")
.arg("/tmp/test_parser_009_book.ruchy")
.assert()
.success();
}
#[test]
#[ignore = "Struct variant field transpile format differs - x:i32 vs x : i32"]
fn test_parser_009_transpile() {
let code = r"
enum Message {
Quit,
Move { x: i32, y: i32 },
Write(String),
}
";
std::fs::write("/tmp/test_parser_009_transpile.ruchy", code).unwrap();
ruchy_cmd()
.arg("transpile")
.arg("/tmp/test_parser_009_transpile.ruchy")
.assert()
.success()
.stdout(predicate::str::contains("Move"))
.stdout(predicate::str::contains("x : i32"))
.stdout(predicate::str::contains("y : i32"));
}