feat: fence review excerpts with language tags

This commit is contained in:
2026-10-25 00:13:35 +02:00
parent c1bff63111
commit 815fcccbe8
6 changed files with 94 additions and 5 deletions
+67
View File
@@ -1,5 +1,72 @@
use super::*;
#[test]
fn text_excerpts_use_detected_languages_and_cannot_close_their_own_fences() {
use crate::plugin::TextPosition;
for (path, content, start_row, expected) in [
(
"source.hon",
"[8]Builtin",
0,
"```hon\n[8]Builtin\n```\nFeedback **outside**\n",
),
(
"source.rs",
"let value = \"界\";\n",
0,
"```rust\nlet value = \"界\";\n```\nFeedback **outside**\n",
),
(
"Makefile",
"all:\n\techo ok",
0,
"```makefile\nall:\n\techo ok\n```\nFeedback **outside**\n",
),
(
"script",
"#!/usr/bin/env python3\nprint('界')\n",
1,
"```python\nprint('界')\n```\nFeedback **outside**\n",
),
(
"unknown.data",
"e\u{301}👩‍💻\n界",
0,
"```\ne\u{301}👩‍💻\n界\n```\nFeedback **outside**\n",
),
(
"example.md",
"```rust\n````\n```",
0,
"`````markdown\n```rust\n````\n```\n`````\nFeedback **outside**\n",
),
] {
let mut review = Review::default();
review.comments.push(Comment {
id: 1,
resolved: false,
body: "Feedback **outside**".into(),
anchor: Anchor {
revision: "snapshot".into(),
path: path.into(),
side: Side::After,
start: TextPosition {
row: start_row,
column: 0,
},
end: TextPosition {
row: content.split('\n').count() - 1,
column: content.rsplit('\n').next().unwrap().graphemes(true).count(),
},
content: content.into(),
},
});
let text = review.format_text(false);
assert!(text.ends_with(expected), "{path}: {text}");
}
}
struct Directory(PathBuf);
impl Drop for Directory {
fn drop(&mut self) {