Implement Phase I tree-walk interpreter for all examples.
Parse functions, calls, returns, branches, loops, tables, and imports so marqdo run passes the examples gold suite (M2–M4). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
69b626e919
commit
a29bf6e97b
12 files changed
+1791
-61
No files matched your search
+53
-25
@@ -1,37 +1,65 @@
|
||||
use std::process::Command;
|
||||
|
||||
#[test]
|
||||
fn cli_runs_and_reports_unimplemented() {
|
||||
fn run(args: &[&str]) -> (i32, String, String) {
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", "examples/hello.mq.md"])
|
||||
.args(args)
|
||||
.output()
|
||||
.expect("failed to run marqdo");
|
||||
let code = output.status.code().unwrap_or(1);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout).into_owned();
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).into_owned();
|
||||
(code, stdout, stderr)
|
||||
}
|
||||
|
||||
assert!(
|
||||
!output.status.success(),
|
||||
"M0/M1 should exit non-zero until eval exists"
|
||||
);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(
|
||||
stderr.contains("not implemented") || stderr.contains("evaluation not implemented"),
|
||||
"stderr was: {stderr}"
|
||||
#[test]
|
||||
fn hello_prints_greeting() {
|
||||
let (code, stdout, stderr) = run(&["run", "examples/hello.mq.md"]);
|
||||
assert_eq!(code, 0, "stderr={stderr}");
|
||||
assert_eq!(stdout.trim_end(), "Hello World!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index_nested_call() {
|
||||
let (code, stdout, stderr) = run(&["run", "examples/index.mq.md"]);
|
||||
assert_eq!(code, 0, "stderr={stderr}");
|
||||
assert_eq!(stdout.trim_end(), "Hello World!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn branch_else_arm() {
|
||||
let (code, stdout, stderr) = run(&["run", "examples/branch.mq.md"]);
|
||||
assert_eq!(code, 0, "stderr={stderr}");
|
||||
assert_eq!(stdout.trim_end(), "零");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn loop_while_and_foreach() {
|
||||
let (code, stdout, stderr) = run(&["run", "examples/loop.mq.md"]);
|
||||
assert_eq!(code, 0, "stderr={stderr}");
|
||||
assert_eq!(
|
||||
stdout.trim_end(),
|
||||
"3\n2\n1\n今天吃苹果\n今天吃梨"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_dump_lines_shows_classification() {
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", "examples/hello.mq.md", "--dump-lines"])
|
||||
.output()
|
||||
.expect("failed to run marqdo");
|
||||
fn collection_foreach() {
|
||||
let (code, stdout, stderr) = run(&["run", "examples/collection.mq.md"]);
|
||||
assert_eq!(code, 0, "stderr={stderr}");
|
||||
assert_eq!(stdout.trim_end(), "苹果\n梨\n桃");
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
assert!(
|
||||
stdout.contains("=== marqdo: lines"),
|
||||
"stdout was: {stdout}"
|
||||
);
|
||||
assert!(stdout.contains("Code"), "expected Code line: {stdout}");
|
||||
assert!(stdout.contains("Comment") || stdout.contains("Blank"), "{stdout}");
|
||||
assert!(stdout.contains("print"), "{stdout}");
|
||||
assert!(!output.status.success());
|
||||
#[test]
|
||||
fn with_import() {
|
||||
let (code, stdout, stderr) = run(&["run", "examples/with-import.mq.md"]);
|
||||
assert_eq!(code, 0, "stderr={stderr}");
|
||||
assert_eq!(stdout.trim_end(), "42\n你好,Marqdo!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hello_dump_lines_still_runs() {
|
||||
let (code, stdout, stderr) = run(&["run", "examples/hello.mq.md", "--dump-lines"]);
|
||||
assert_eq!(code, 0, "stderr={stderr}");
|
||||
assert!(stdout.contains("=== marqdo: lines"));
|
||||
assert!(stdout.contains("Hello World!"));
|
||||
}
|
||||
Reference in new issue
Block a user