Files
core/test/rust/native/inspection/documentation.rs
T
2026-11-03 03:32:07 +00:00

117 lines
4.0 KiB
Rust

use super::*;
#[test]
fn documentation_heading_positions_preserve_unicode_fences_and_crlf() {
let directory = Directory::new();
let root = directory.0.join("app");
dever::compiler::project::create(&root).unwrap();
let path = root.join("module/hello/greeting/doc/greeting.md");
let text = "# 中文说明\r\n\r\n```markdown\r\n## not.a.symbol\r\n```\r\n\r\n## hello.greeting.greet\r\n\r\n真实说明。\r\n";
std::fs::write(path, text).unwrap();
let index = Project::load(&root).unwrap().inspect().unwrap();
assert!(index.documentation_errors.is_empty());
let description = index
.documentation
.iter()
.find(|description| description.symbol == "hello.greeting.greet")
.unwrap();
assert_eq!(description.line, 6);
assert_eq!(description.markdown, "真实说明。");
}
#[test]
fn documentation_binds_clauses_without_entering_program_semantics() {
let directory = Directory::new();
let root = directory.0.join("app");
dever::compiler::project::create(&root).unwrap();
let path = root.join("module/hello/greeting/doc/greeting.md");
let original = std::fs::read_to_string(&path).unwrap();
let project = Project::load(&root).unwrap();
let before = project.api_snapshot().unwrap();
let index = project.inspect().unwrap();
assert!(
index.documentation_errors.is_empty(),
"{:?}",
index.documentation_errors
);
let symbol = index
.symbols
.iter()
.find(|symbol| symbol.name == "hello.greeting.greet")
.unwrap();
assert_eq!(symbol.signatures, ["greet(name: Text) (message: Text)"]);
let description = index
.documentation
.iter()
.find(|doc| doc.symbol == symbol.name)
.unwrap();
assert!(description.markdown.contains("按原样保留"));
assert_eq!(
index.documentation_files[description.file].path,
path.to_string_lossy()
);
std::fs::write(
&path,
format!("{original}\n```markdown\n## not.a.symbol\n```\n\n> ## quoted.symbol\n\n- Nested\n\n ## nested.symbol\n"),
)
.unwrap();
assert!(project.inspect().unwrap().documentation_errors.is_empty());
std::fs::write(
&path,
format!("{original}\n## hello.greeting.missing\n\n过期说明。\n"),
)
.unwrap();
let changed = project.inspect().unwrap();
assert!(
changed
.documentation_errors
.iter()
.any(|error| error.contains("hello.greeting.missing"))
);
assert_eq!(project.api_snapshot().unwrap(), before);
project.check().unwrap();
std::fs::write(&path, original).unwrap();
std::fs::write(
root.join("module/hello/greeting/doc/duplicate.md"),
"## hello.greeting.greet\n\n重复。\n",
)
.unwrap();
let duplicate = project.inspect().unwrap();
assert!(
duplicate
.documentation_errors
.iter()
.any(|error| error.contains("duplicate documentation"))
);
assert!(
!duplicate
.documentation
.iter()
.any(|doc| doc.symbol == "hello.greeting.greet")
);
let output = Command::new(env!("CARGO_BIN_EXE_dever"))
.args(["inspect", root.to_str().unwrap(), "--links", "--check"])
.output()
.unwrap();
assert!(!output.status.success());
assert!(String::from_utf8_lossy(&output.stderr).contains("duplicate documentation"));
}
#[test]
fn old_source_format_is_rejected_instead_of_silently_skipped() {
let directory = Directory::new();
let root = directory.0.join("app");
dever::compiler::project::create(&root).unwrap();
let path = root.join("module/hello/greeting/domain.dever.md");
std::fs::write(&path, "# Old source\n\n```dever\nunused() () {}\n```\n").unwrap();
assert!(Project::load(&root).err().unwrap().contains("doc/"));
assert!(Project::load(&path).err().unwrap().contains("project root"));
assert!(
dever::compiler::format::project(&root, true)
.unwrap_err()
.contains("doc/")
);
}