feat: adopt marqdo 3.0.0-rc.4 public analysis boundary
This commit is contained in:
1 parent
769550b14b
commit
fe18df6c4b
74 files changed
+7618
-5368
No files matched your search
+29
-46
@@ -1,24 +1,27 @@
|
||||
mod common;
|
||||
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use common::{document, require_core};
|
||||
use marqdo_lint::{
|
||||
alignment::{
|
||||
align_function, statement_count, ArmRole, BodyOwner, JumpKind, ReadableControlTree,
|
||||
},
|
||||
input::{AnalysisStatus, MarqdoRunner, ProjectInput},
|
||||
model::{AnalysisFunction, ExecutionProjection, MarkdownTree, SourceSnapshot},
|
||||
model::ExecutionProjection,
|
||||
};
|
||||
use serde_json::Value;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
fn frozen(stem: &str) -> (MarkdownTree, AnalysisFunction) {
|
||||
let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/rc2");
|
||||
let source = SourceSnapshot::load(dir.join(format!("{stem}.mq.md"))).unwrap();
|
||||
let read = |kind| -> Value {
|
||||
serde_json::from_slice(&fs::read(dir.join(format!("{stem}.{kind}.json"))).unwrap()).unwrap()
|
||||
};
|
||||
let markdown = MarkdownTree::from_json(read("ast")["ast"].clone(), &source).unwrap();
|
||||
let projection = ExecutionProjection::from_json(read("analysis")).unwrap();
|
||||
let analysis = projection.modules[0].functions[0].clone();
|
||||
(markdown, analysis)
|
||||
fn frozen(
|
||||
stem: &str,
|
||||
) -> (
|
||||
marqdo_lint::model::MarkdownTree,
|
||||
marqdo_lint::model::AnalysisFunction,
|
||||
) {
|
||||
let document = document(stem);
|
||||
let module = document.module.as_ref().unwrap();
|
||||
let analysis = module.functions[0].clone();
|
||||
(document.markdown, analysis)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -117,11 +120,11 @@ fn rejects_a_jump_projected_in_the_wrong_body() {
|
||||
assert!(tree.issues[0].contains("所属语句体"), "{:?}", tree.issues);
|
||||
}
|
||||
|
||||
fn live_alignment(runner: &MarqdoRunner, source: &str) -> (u64, ReadableControlTree) {
|
||||
fn live_alignment(runner: &MarqdoRunner, source: &str) -> ReadableControlTree {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let file = dir.path().join("case.mq.md");
|
||||
fs::write(&file, source).unwrap();
|
||||
let project = ProjectInput::load(file, runner).unwrap();
|
||||
let project = ProjectInput::load(file, runner, false).unwrap();
|
||||
assert_eq!(
|
||||
project.analysis_status,
|
||||
AnalysisStatus::Complete,
|
||||
@@ -134,19 +137,18 @@ fn live_alignment(runner: &MarqdoRunner, source: &str) -> (u64, ReadableControlT
|
||||
&document.module.as_ref().unwrap().functions[0],
|
||||
);
|
||||
assert!(tree.complete, "{:?}", tree.issues);
|
||||
(project.analysis.unwrap().schema_version, tree)
|
||||
tree
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn separate_else_and_if_payloads_open_nested_groups() {
|
||||
let Ok(binary) = std::env::var("MARQDO_BIN") else {
|
||||
let Some(binary) = require_core() else {
|
||||
return;
|
||||
};
|
||||
let runner = MarqdoRunner::discover(Some(Path::new(&binary))).unwrap();
|
||||
let source =
|
||||
"## @exec main\n\n`if false`\n\n`else` `if true`\n\n*return 1*\n\n`end`\n\n`end`\n";
|
||||
let (version, tree) = live_alignment(&runner, source);
|
||||
assert_eq!(version, 2);
|
||||
let tree = live_alignment(&runner, source);
|
||||
let [outer, inner] = tree.controls.as_slice() else {
|
||||
panic!("expected two groups")
|
||||
};
|
||||
@@ -164,32 +166,13 @@ fn separate_else_and_if_payloads_open_nested_groups() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rc2_keeps_an_explicit_empty_else_without_inventing_one() {
|
||||
let Ok(binary) = std::env::var("MARQDO_BIN") else {
|
||||
return;
|
||||
};
|
||||
let runner = MarqdoRunner::discover(Some(Path::new(&binary))).unwrap();
|
||||
if !std::process::Command::new(runner.binary())
|
||||
.arg("--version")
|
||||
.output()
|
||||
.unwrap()
|
||||
.stdout
|
||||
.ends_with(b"3.0.0-rc.2\n")
|
||||
{
|
||||
return;
|
||||
}
|
||||
for fallback in ["", "4. `else`:空回退。\n\n"] {
|
||||
let source = format!("## @exec main\n\n1. `if false`\n *return 1*\n2. `else if true`\n *return 2*\n3. `else if false`\n *return 3*\n{fallback}\n`end`\n");
|
||||
let (version, tree) = live_alignment(&runner, &source);
|
||||
assert_eq!(version, 2);
|
||||
let arms = &tree.controls[0].arms;
|
||||
if fallback.is_empty() {
|
||||
assert_eq!(arms.len(), 3);
|
||||
assert_eq!(arms[2].role, ArmRole::ElseIf);
|
||||
} else {
|
||||
assert_eq!(arms.len(), 4);
|
||||
assert_eq!(arms[3].role, ArmRole::Else);
|
||||
assert!(arms[3].analysis_index.is_none());
|
||||
}
|
||||
}
|
||||
fn saved_artifact_has_one_analysis_revision() {
|
||||
let projection = ExecutionProjection::from_json(common::analysis_value("multi-arm")).unwrap();
|
||||
assert_eq!(projection.schema_version, 3);
|
||||
assert_eq!(projection.modules[0].functions[0].effects, vec!["unknown"]);
|
||||
assert_eq!(
|
||||
projection.modules[0].units[0].kind,
|
||||
marqdo_lint::model::UnitKind::Root
|
||||
);
|
||||
let _ = json!(null);
|
||||
}
|
||||
Reference in new issue
Block a user