Files
marqdo/tests/occlusion.rs
T
cflmy 1a94cc8490 feat(check): M2.5 遮蔽标签诊断 — label.missing(error) / label.empty_payload(warning)
新增 src/label.rs:
- OcclusionSite { label, has_payload, line, unit }
- collect(module):遍历函数/分支/循环/表达式收集遮蔽点(描述只读,不产生读引用)
- check(module, path):产出两条诊断

两条诊断:
- label.missing(error):[](...) 描述为空 —— 写一句人话,或改用不带遮蔽的写法
- label.empty_payload(warning):[描述]() 载荷为空 —— 写清桩返回什么(None/0),或补实现
warning 不影响退出码;JSON 出口自动继承既有 schema(含 doc_quote/span/suggestion)。

接入 check_module:walk 之后 extend(crate::label::check(..)),保持一行;
M4(引用一致性)与 M9(检索)都往 label 模块加,check 不再膨胀。

测试:
- 3 个集成(tests/occlusion.rs):空描述 exit 1、空载荷 exit 0、干净样例无诊断
- 全量 cargo test --release:578 passed / 0 failed(M2 后 575 + 3)
反向验证:干净样例必须零输出,证明不会误响。

实测:
  MARQDO_MARKUP=occlusion marqdo check empty-label.mq.md    # 1 error, exit 1
  MARQDO_MARKUP=occlusion marqdo check empty-payload.mq.md  # 1 warning, exit 0

文档:doc/design/change-m25-label-diagnostics.md
2026-10-22 15:13:33 +08:00

86 lines
2.9 KiB
Rust

//! `<TAB>` M2: occlusion syntax end-to-end (CLI + `MARQDO_MARKUP=occlusion`).
//!
//! The mode flag keeps `[键](集合)` (classic index) intact until M7 migrates the
//! corpus; these tests pin both sides of the switch.
use std::process::Command;
fn run(path: &str, markup: Option<&str>) -> (i32, String, String) {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_marqdo"));
cmd.args(["run", path]);
if let Some(m) = markup {
cmd.env("MARQDO_MARKUP", m);
}
let out = cmd.output().expect("run marqdo");
(
out.status.code().unwrap_or(1),
String::from_utf8_lossy(&out.stdout).into_owned(),
String::from_utf8_lossy(&out.stderr).into_owned(),
)
}
#[test]
fn occlusion_value_is_payload() {
let (code, stdout, stderr) = run("tests/occlusion/value.mq.md", Some("occlusion"));
assert_eq!(code, 0, "stderr={stderr}");
assert_eq!(stdout.trim_end(), "a=2\nb=42\nc=True");
}
#[test]
fn occlusion_off_keeps_classic_index() {
let (code, stdout, stderr) = run("tests/occlusion/classic-index.mq.md", None);
assert_eq!(code, 0, "stderr={stderr}");
assert_eq!(stdout.trim_end(), "值");
}
#[test]
fn occlusion_mode_rejects_legacy_index_shape() {
// In occlusion mode `[键](集合)` is read as an occlusion whose payload is the
// collection — i.e. it returns the *whole* map, not the member. This is why
// M7 must migrate before flipping the default; here we only pin that the
// shape no longer means "index".
let (code, stdout, stderr) = run("tests/occlusion/classic-index.mq.md", Some("occlusion"));
assert_eq!(code, 0, "stderr={stderr}");
assert_ne!(stdout.trim_end(), "值", "occlusion mode must not index");
}
// ---- M2.5: label diagnostics (`label.missing` / `label.empty_payload`) ----
fn check(path: &str, markup: &str) -> (i32, String) {
let out = Command::new(env!("CARGO_BIN_EXE_marqdo"))
.args(["check", path])
.env("MARQDO_MARKUP", markup)
.output()
.expect("run marqdo check");
(
out.status.code().unwrap_or(1),
format!(
"{}{}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
),
)
}
#[test]
fn label_missing_is_an_error() {
let (code, text) = check("tests/occlusion/empty-label.mq.md", "occlusion");
assert_eq!(code, 1, "text={text}");
assert!(text.contains("遮蔽缺少描述"), "text={text}");
}
#[test]
fn label_empty_payload_is_a_warning() {
let (code, text) = check("tests/occlusion/empty-payload.mq.md", "occlusion");
assert_eq!(code, 0, "warnings must not fail the build: text={text}");
assert!(text.contains("空载荷遮蔽"), "text={text}");
}
#[test]
fn label_ok_has_no_diagnostics() {
let (code, text) = check("tests/occlusion/clean.mq.md", "occlusion");
assert_eq!(code, 0, "text={text}");
assert!(!text.contains("空载荷"), "text={text}");
assert!(!text.contains("缺少描述"), "text={text}");
}