-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtui_test.go
More file actions
156 lines (133 loc) · 4.1 KB
/
tui_test.go
File metadata and controls
156 lines (133 loc) · 4.1 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// SPDX-License-Identifier: MIT
package main
import "testing"
func TestCycleRanker(t *testing.T) {
order := []string{"simple", "tfidf", "bm25", "structural", "min"}
cfg := DefaultConfig()
m := &model{cfg: &cfg}
for i, want := range order {
m.cfg.Ranker = order[i]
m.cycleRanker()
expected := order[(i+1)%len(order)]
if m.cfg.Ranker != expected {
t.Errorf("cycleRanker from %q: got %q, want %q", want, m.cfg.Ranker, expected)
}
}
}
func TestCycleRankerUnknownResetsToSimple(t *testing.T) {
cfg := DefaultConfig()
m := &model{cfg: &cfg}
m.cfg.Ranker = "unknown"
m.cycleRanker()
if m.cfg.Ranker != "simple" {
t.Errorf("cycleRanker from unknown: got %q, want %q", m.cfg.Ranker, "simple")
}
}
func TestCycleCodeFilter(t *testing.T) {
cfg := DefaultConfig()
m := &model{cfg: &cfg}
// default → only-code
m.cfg.OnlyCode = false
m.cfg.OnlyComments = false
m.cfg.OnlyStrings = false
m.cycleCodeFilter()
if !m.cfg.OnlyCode || m.cfg.OnlyComments || m.cfg.OnlyStrings {
t.Errorf("step 1: expected OnlyCode=true, OnlyComments=false, OnlyStrings=false")
}
// only-code → only-comments
m.cycleCodeFilter()
if m.cfg.OnlyCode || !m.cfg.OnlyComments || m.cfg.OnlyStrings {
t.Errorf("step 2: expected OnlyCode=false, OnlyComments=true, OnlyStrings=false")
}
// only-comments → only-strings
m.cycleCodeFilter()
if m.cfg.OnlyCode || m.cfg.OnlyComments || !m.cfg.OnlyStrings {
t.Errorf("step 3: expected OnlyCode=false, OnlyComments=false, OnlyStrings=true")
}
// only-strings → default
m.cycleCodeFilter()
if m.cfg.OnlyCode || m.cfg.OnlyComments || m.cfg.OnlyStrings {
t.Errorf("step 4: expected OnlyCode=false, OnlyComments=false, OnlyStrings=false")
}
}
func TestCycleCodeFilterAutoSelectsStructuralRanker(t *testing.T) {
cfg := DefaultConfig()
m := &model{cfg: &cfg}
m.cfg.Ranker = "bm25"
m.cfg.OnlyCode = false
m.cfg.OnlyComments = false
m.cycleCodeFilter() // → only-code
if m.cfg.Ranker != "structural" {
t.Errorf("expected ranker=structural when only-code active, got %q", m.cfg.Ranker)
}
}
func TestCycleGravity(t *testing.T) {
order := []string{"off", "low", "default", "logic", "brain"}
cfg := DefaultConfig()
m := &model{cfg: &cfg}
for i, want := range order {
m.cfg.GravityIntent = order[i]
m.cycleGravity()
expected := order[(i+1)%len(order)]
if m.cfg.GravityIntent != expected {
t.Errorf("cycleGravity from %q: got %q, want %q", want, m.cfg.GravityIntent, expected)
}
}
}
func TestCycleGravityUnknownResetsToOff(t *testing.T) {
cfg := DefaultConfig()
m := &model{cfg: &cfg}
m.cfg.GravityIntent = "unknown"
m.cycleGravity()
if m.cfg.GravityIntent != "off" {
t.Errorf("cycleGravity from unknown: got %q, want %q", m.cfg.GravityIntent, "off")
}
}
func TestHighlightMatchOnly_NegativeIndex(t *testing.T) {
// Ensure negative loc[0] doesn't panic
line := "hello world"
locs := [][]int{{-5, 3}, {6, 11}}
result := highlightMatchOnly(line, locs, false)
if result == "" {
t.Error("expected non-empty result")
}
}
func TestHighlightMatchOnly_EmptyLocs(t *testing.T) {
line := "hello world"
result := highlightMatchOnly(line, nil, false)
if result == "" {
t.Error("expected non-empty result for nil locs")
}
}
func TestHighlightMatchOnly_LocBeyondLine(t *testing.T) {
line := "hello"
locs := [][]int{{0, 100}}
result := highlightMatchOnly(line, locs, false)
if result == "" {
t.Error("expected non-empty result when loc extends beyond line")
}
}
func TestCodeFilterLabel(t *testing.T) {
cfg := DefaultConfig()
m := &model{cfg: &cfg}
m.cfg.OnlyCode = false
m.cfg.OnlyComments = false
m.cfg.OnlyStrings = false
if got := m.codeFilterLabel(); got != "default" {
t.Errorf("expected 'default', got %q", got)
}
m.cfg.OnlyCode = true
if got := m.codeFilterLabel(); got != "only-code" {
t.Errorf("expected 'only-code', got %q", got)
}
m.cfg.OnlyCode = false
m.cfg.OnlyComments = true
if got := m.codeFilterLabel(); got != "only-comments" {
t.Errorf("expected 'only-comments', got %q", got)
}
m.cfg.OnlyComments = false
m.cfg.OnlyStrings = true
if got := m.codeFilterLabel(); got != "only-strings" {
t.Errorf("expected 'only-strings', got %q", got)
}
}