MCPcopy
hub / github.com/peco/peco / TestDoInvertSelectionWithLineAtError

Function TestDoInvertSelectionWithLineAtError

action_test.go:137–172  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestDoInvertSelectionWithLineAtError(t *testing.T) {
138 state := New()
139 state.screen = NewDummyScreen()
140 state.configReader = nopConfigReader
141
142 rh := &recordingHub{}
143 state.hub = rh
144
145 // Create lines and a buffer where index 1 fails
146 l0 := line.NewRaw(1, "line0", false, false)
147 l1 := line.NewRaw(2, "line1", false, false)
148 l2 := line.NewRaw(3, "line2", false, false)
149
150 buf := &failingBuffer{
151 lines: []line.Line{l0, l1, l2},
152 failAt: map[int]bool{1: true},
153 }
154 state.currentLineBuffer = buf
155
156 // Pre-select lines 0 and 2, so inversion should deselect them
157 state.Selection().Add(l0)
158 state.Selection().Add(l2)
159
160 // This should NOT panic despite LineAt returning nil for index 1.
161 require.NotPanics(t, func() {
162 doInvertSelection(context.Background(), state, Event{})
163 }, "doInvertSelection must not panic when LineAt returns an error")
164
165 // Line 0 was selected → should now be deselected.
166 // Line 1 failed → skip (remain unselected).
167 // Line 2 was selected → should now be deselected.
168 sel := state.Selection()
169 require.False(t, sel.Has(l0), "line 0 was selected, should be deselected after inversion")
170 require.False(t, sel.Has(l1), "line 1 should not be affected (LineAt failed)")
171 require.False(t, sel.Has(l2), "line 2 was selected, should be deselected after inversion")
172}
173
174func TestActionFunc(t *testing.T) {
175 called := 0

Callers

nothing calls this directly

Calls 7

NewRawFunction · 0.92
NewDummyScreenFunction · 0.85
doInvertSelectionFunction · 0.85
SelectionMethod · 0.80
HasMethod · 0.80
NewFunction · 0.70
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…