summaryrefslogtreecommitdiff
path: root/internal/lsp/handlers_helpers_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-18 19:03:27 +0300
committerPaul Buetow <paul@buetow.org>2025-08-18 19:03:27 +0300
commitadd957285a5ed6bafbfe2ec5b88060fc01ed7082 (patch)
treee84b6263e0cbaae4029a339bf2644c032f7326c6 /internal/lsp/handlers_helpers_test.go
parent4fd086f3807f4b5b1fa414b2d1d6ec0f24c3f9b4 (diff)
lsp: strip Markdown code fences from LLM outputs (completions and code actions)
Diffstat (limited to 'internal/lsp/handlers_helpers_test.go')
-rw-r--r--internal/lsp/handlers_helpers_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/lsp/handlers_helpers_test.go b/internal/lsp/handlers_helpers_test.go
index 84dce77..f9ed18a 100644
--- a/internal/lsp/handlers_helpers_test.go
+++ b/internal/lsp/handlers_helpers_test.go
@@ -50,3 +50,22 @@ func TestPromptRemovalEditsForLine_WholeLine(t *testing.T) {
}
}
+func TestStripCodeFences(t *testing.T) {
+ cases := []struct{
+ name string
+ in string
+ want string
+ }{
+ {"no fences", "package main\nfunc x(){}", "package main\nfunc x(){}"},
+ {"triple backticks no lang", "```\nA\nB\n```", "A\nB"},
+ {"triple backticks with lang", "```go\nfmt.Println(\"hi\")\n```", "fmt.Println(\"hi\")"},
+ {"leading/trailing spaces", " \n```python\nprint('x')\n```\n ", "print('x')"},
+ {"single line fenced", "```go\npackage main\n```", "package main"},
+ }
+ for _, tc := range cases {
+ got := stripCodeFences(tc.in)
+ if got != tc.want {
+ t.Fatalf("%s: got %q want %q", tc.name, got, tc.want)
+ }
+ }
+}