-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexer_test.go
More file actions
58 lines (52 loc) · 1.39 KB
/
Copy pathindexer_test.go
File metadata and controls
58 lines (52 loc) · 1.39 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package contexting
import (
"os"
"path/filepath"
"testing"
)
func TestBuildIndexUsesCacheAndLexicalSynonyms(t *testing.T) {
tmpDir := t.TempDir()
if err := os.MkdirAll(filepath.Join(tmpDir, "config"), 0o755); err != nil {
t.Fatalf("mkdir: %v", err)
}
if err := os.WriteFile(filepath.Join(tmpDir, "config", "localStore.go"), []byte("package config"), 0o644); err != nil {
t.Fatalf("write: %v", err)
}
result, err := BuildIndex(BuildOptions{
RootPath: tmpDir,
IgnoredPaths: BuildIgnoreMap(nil),
SynonymsPerName: 4,
SynonymCache: SynonymResponse{
"config": {"settings", "file", "state"},
},
})
if err != nil {
t.Fatalf("BuildIndex error: %v", err)
}
configNode := result.Index.Tree.Children["config"]
if configNode == nil {
t.Fatalf("expected config node")
}
if len(configNode.Synonyms) == 0 {
t.Fatalf("expected synonyms on config node")
}
foundSettings := false
for _, syn := range configNode.Synonyms {
if syn == "settings" {
foundSettings = true
}
if syn == "file" {
t.Fatalf("expected filtered synonyms, got %v", configNode.Synonyms)
}
}
if !foundSettings {
t.Fatalf("expected cached synonym 'settings' in %v", configNode.Synonyms)
}
fileNode := configNode.Children["localStore.go"]
if fileNode == nil {
t.Fatalf("expected localStore.go node")
}
if len(fileNode.Synonyms) == 0 {
t.Fatalf("expected lexical synonyms on localStore.go")
}
}