summaryrefslogtreecommitdiff
path: root/internal/lsp/handlers_helpers_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-18 09:28:48 +0300
committerPaul Buetow <paul@buetow.org>2025-08-18 09:28:48 +0300
commit96ace6c7019a914e21b25fa94ddfc4ee9239c2fb (patch)
tree30550bcab30c91e917a4d8b3feccda829a364437 /internal/lsp/handlers_helpers_test.go
parent6d29ac7e4b2604b5c7df50f33f8ef2357709faf2 (diff)
refactor(lsp,llm,hexailsp,appconfig): split long funcs; add tests
- Extract helpers to keep funcs <=50 lines; no behavior changes - Add tests for prompt removal, code actions, and LLM request builders - Table-drive TestInParamList; run gofmt
Diffstat (limited to 'internal/lsp/handlers_helpers_test.go')
-rw-r--r--internal/lsp/handlers_helpers_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/lsp/handlers_helpers_test.go b/internal/lsp/handlers_helpers_test.go
new file mode 100644
index 0000000..84dce77
--- /dev/null
+++ b/internal/lsp/handlers_helpers_test.go
@@ -0,0 +1,52 @@
+package lsp
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestHasDoubleSemicolonTrigger(t *testing.T) {
+ cases := []struct{
+ line string
+ want bool
+ }{
+ {";;todo; remove this", true},
+ {"prefix ;;x; suffix", true},
+ {";; spaced ;", false},
+ {"no markers", false},
+ {";;x ; space before close", false},
+ }
+ for _, tc := range cases {
+ got := hasDoubleSemicolonTrigger(tc.line)
+ if got != tc.want {
+ t.Fatalf("hasDoubleSemicolonTrigger(%q)=%v want %v", tc.line, got, tc.want)
+ }
+ }
+}
+
+func TestCollectSemicolonMarkers(t *testing.T) {
+ line := "keep ;ok; this and ;another; that"
+ edits := collectSemicolonMarkers(line, 7)
+ if len(edits) != 2 {
+ t.Fatalf("expected 2 edits, got %d", len(edits))
+ }
+ // Validate the first edit aligns with ;ok;
+ start := strings.Index(line, ";ok;")
+ if start < 0 { t.Fatalf("test setup: missing ;ok;") }
+ if edits[0].Range.Start.Line != 7 || edits[0].Range.Start.Character != start {
+ t.Fatalf("first edit start got line=%d char=%d want line=7 char=%d", edits[0].Range.Start.Line, edits[0].Range.Start.Character, start)
+ }
+}
+
+func TestPromptRemovalEditsForLine_WholeLine(t *testing.T) {
+ line := ";;todo; remove this whole line"
+ edits := promptRemovalEditsForLine(line, 3)
+ if len(edits) != 1 {
+ t.Fatalf("expected 1 whole-line edit, got %d", len(edits))
+ }
+ e := edits[0]
+ if e.Range.Start.Line != 3 || e.Range.End.Line != 3 || e.Range.Start.Character != 0 || e.Range.End.Character != len(line) {
+ t.Fatalf("unexpected range for whole-line removal: %+v", e.Range)
+ }
+}
+