-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchunker_test.go
More file actions
94 lines (75 loc) · 1.84 KB
/
Copy pathchunker_test.go
File metadata and controls
94 lines (75 loc) · 1.84 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package chisel
import (
"context"
"testing"
)
// mockProvider implements Provider for testing.
type mockProvider struct {
lang Language
chunks []Chunk
err error
}
func (m *mockProvider) Language() Language {
return m.lang
}
func (m *mockProvider) Chunk(_ context.Context, _ string, _ []byte) ([]Chunk, error) {
return m.chunks, m.err
}
func TestNew(t *testing.T) {
p1 := &mockProvider{lang: Go}
p2 := &mockProvider{lang: Python}
c := New(p1, p2)
if !c.HasProvider(Go) {
t.Error("expected Go provider to be registered")
}
if !c.HasProvider(Python) {
t.Error("expected Python provider to be registered")
}
if c.HasProvider(Rust) {
t.Error("expected Rust provider to not be registered")
}
}
func TestChunker_Register(t *testing.T) {
c := New()
if c.HasProvider(Go) {
t.Error("expected no Go provider initially")
}
c.Register(&mockProvider{lang: Go})
if !c.HasProvider(Go) {
t.Error("expected Go provider after registration")
}
}
func TestChunker_Chunk(t *testing.T) {
expected := []Chunk{
{Symbol: "TestFunc", Kind: KindFunction, StartLine: 1, EndLine: 5},
}
c := New(&mockProvider{
lang: Go,
chunks: expected,
})
chunks, err := c.Chunk(context.Background(), Go, "test.go", []byte("package main"))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(chunks) != len(expected) {
t.Errorf("got %d chunks, want %d", len(chunks), len(expected))
}
}
func TestChunker_Chunk_NoProvider(t *testing.T) {
c := New()
_, err := c.Chunk(context.Background(), Go, "test.go", []byte("package main"))
if err == nil {
t.Error("expected error for missing provider")
}
}
func TestChunker_Languages(t *testing.T) {
c := New(
&mockProvider{lang: Go},
&mockProvider{lang: Python},
&mockProvider{lang: Rust},
)
langs := c.Languages()
if len(langs) != 3 {
t.Errorf("got %d languages, want 3", len(langs))
}
}