refactor: scope markup compatibility per invocation
This commit is contained in:
1 parent
eac9b45263
commit
939e23ee88
9 files changed
+94
-67
No files matched your search
@@ -164,6 +164,10 @@ const BIND_BARE: &str = "\
|
||||
";
|
||||
|
||||
const KEY_WRONG: &str = "\
|
||||
---
|
||||
markup: classic
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 字段 | 类型 | 可空 |
|
||||
@@ -180,6 +184,10 @@ const KEY_WRONG: &str = "\
|
||||
";
|
||||
|
||||
const KEY_RIGHT: &str = "\
|
||||
---
|
||||
markup: classic
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 字段 | 类型 | 可空 |
|
||||
@@ -196,6 +204,10 @@ const KEY_RIGHT: &str = "\
|
||||
";
|
||||
|
||||
const KEY_BARE: &str = "\
|
||||
---
|
||||
markup: classic
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`用户` =
|
||||
|
||||
+11
-5
@@ -215,16 +215,21 @@ fn drills() -> Vec<Drill> {
|
||||
]
|
||||
}
|
||||
|
||||
fn classic(src: &str) -> String {
|
||||
format!("---\nmarkup: classic\n---\n\n{src}")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drift_cases_all_reported() {
|
||||
let all = drills();
|
||||
let total = all.len();
|
||||
let mut caught = 0;
|
||||
for d in &all {
|
||||
let src = classic(d.src);
|
||||
let diags = if d.runtime {
|
||||
diagnose(Verify::Run(d.code), d.src, &format!("drift_{}", d.name))
|
||||
diagnose(Verify::Run(d.code), &src, &format!("drift_{}", d.name))
|
||||
} else {
|
||||
static_diags(d.src)
|
||||
static_diags(&src)
|
||||
};
|
||||
let hit = diags.iter().any(|v| v["code"].as_str() == Some(d.code));
|
||||
assert!(
|
||||
@@ -240,15 +245,16 @@ fn drift_cases_all_reported() {
|
||||
#[test]
|
||||
fn negative_controls_zero_false_positives() {
|
||||
// 1. 被绑定的 `字段|类型|可空` 数据表 = 数据(web_db_migration 式)——绝不能被当契约吃掉。
|
||||
let diags = diagnose(Verify::Run(""), SRC_BOUND_DATA, "drill_neg_bound");
|
||||
let diags = diagnose(Verify::Run(""), &classic(SRC_BOUND_DATA), "drill_neg_bound");
|
||||
assert!(
|
||||
diags.iter().all(|v| !v["code"].as_str().unwrap_or("").starts_with("contract.")),
|
||||
"绑定数据表被误当契约: {diags:?}"
|
||||
);
|
||||
// 2. 干净契约 + 对值 ⇒ 静态零诊断、运行零诊断。
|
||||
let diags = static_diags(SRC_OK);
|
||||
let src_ok = classic(SRC_OK);
|
||||
let diags = static_diags(&src_ok);
|
||||
assert!(diags.is_empty(), "干净契约被误报(静态): {diags:?}");
|
||||
let diags = diagnose(Verify::Run(""), SRC_OK, "drill_neg_ok");
|
||||
let diags = diagnose(Verify::Run(""), &src_ok, "drill_neg_ok");
|
||||
assert!(diags.is_empty(), "干净契约被误报(运行): {diags:?}");
|
||||
eprintln!("负对照误报 = 0/2 = 0%");
|
||||
}
|
||||
+1
-1
@@ -21,7 +21,7 @@ fn fixture() -> (std::path::PathBuf, String) {
|
||||
let dir = std::env::temp_dir().join(format!("marqdo-migrate-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("demo.mq.md");
|
||||
let src = "---\nimport json:lib/json.mq.md\n---\n\n# main\n\n`表` = > json.parse text={\"键\":\"值\"}\n**a = [键](`表`)**\n> print text=\"a=\" + `a`\n";
|
||||
let src = "---\nmarkup: classic\nimport json:lib/json.mq.md\n---\n\n# main\n\n`表` = > json.parse text={\"键\":\"值\"}\n**a = [键](`表`)**\n> print text=\"a=\" + `a`\n";
|
||||
std::fs::write(&path, src).unwrap();
|
||||
(path, src.to_string())
|
||||
}
|
||||
|
||||
+9
-14
@@ -1,7 +1,5 @@
|
||||
//! `<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.
|
||||
//! Occlusion syntax end-to-end. Grammar is declared by each document, not a
|
||||
//! process environment variable, so imports and MLSP requests stay isolated.
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
@@ -27,21 +25,17 @@ fn occlusion_value_is_payload() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn occlusion_off_keeps_classic_index() {
|
||||
fn migrated_index_uses_access_without_a_process_mode() {
|
||||
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"));
|
||||
fn declared_occlusion_ignores_legacy_environment_switches() {
|
||||
let (code, stdout, stderr) = run("tests/occlusion/classic-index.mq.md", Some("classic"));
|
||||
assert_eq!(code, 0, "stderr={stderr}");
|
||||
assert_ne!(stdout.trim_end(), "值", "occlusion mode must not index");
|
||||
assert_eq!(stdout.trim_end(), "值");
|
||||
}
|
||||
|
||||
// ---- M2.5: label diagnostics (`label.missing` / `label.empty_payload`) ----
|
||||
@@ -195,10 +189,11 @@ fn mlsp_session(reqs: &[&str]) -> Vec<String> {
|
||||
}
|
||||
|
||||
fn repair_req(src: &str, new_line: &str) -> String {
|
||||
let src_json = serde_json::to_string(src).unwrap();
|
||||
let src = format!("---\nmarkup: occlusion\n---\n\n{src}");
|
||||
let src_json = serde_json::to_string(&src).unwrap();
|
||||
let line_json = serde_json::to_string(new_line).unwrap();
|
||||
format!(
|
||||
r#"{{"id":1,"method":"repair_apply","params":{{"source":{src_json},"ranges":[[3,3]],"edits":[{{"op":"replace","line":3,"text":{line_json}}}],"check_labels":true}}}}"#
|
||||
r#"{{"id":1,"method":"repair_apply","params":{{"source":{src_json},"ranges":[[7,7]],"edits":[{{"op":"replace","line":7,"text":{line_json}}}],"check_labels":true}}}}"#
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
---
|
||||
title: classic index still works
|
||||
markup: occlusion
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**表 = > json.parse text={"键":"值"}**
|
||||
**v = [键](`表`)**
|
||||
**v = access(`表`, "键")**
|
||||
> print text=`v`
|
||||
Reference in new issue
Block a user