blob: 7ceb9e62af4610a49768a3440c9ee0f9bb2835de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package lsp
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestResolveGoTest_AppendsToExisting(t *testing.T) {
s := newTestServer()
dir := t.TempDir()
src := filepath.Join(dir, "m.go")
uri := "file://" + src
s.setDocument(uri, "package m\n\nfunc F(){}\n")
// Create existing test file
testPath := filepath.Join(dir, "m_test.go")
if err := os.WriteFile(testPath, []byte("package m\n\nimport \"testing\"\n\n"), 0o644); err != nil {
t.Fatal(err)
}
// LLM path to increase generateGoTestFunction coverage
s.llmClient = fakeLLM{resp: "func TestF(t *testing.T) {}"}
we, testURI, jump, ok := s.resolveGoTest(uri, Position{Line: 2})
if !ok || len(we.Changes) == 0 {
t.Fatalf("expected append edit")
}
if !strings.HasSuffix(testURI, "_test.go") {
t.Fatalf("unexpected uri: %s", testURI)
}
edits := we.Changes[testURI]
if len(edits) != 1 || !strings.Contains(edits[0].NewText, "TestF") {
t.Fatalf("expected append with TestF")
}
if jump.Start.Line < 0 {
t.Fatalf("expected non-negative jump line")
}
}
|