MCPcopy
hub / github.com/junegunn/fzf / TestBind

Function TestBind

src/options_test.go:252–300  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

250}
251
252func TestBind(t *testing.T) {
253 keymap := defaultKeymap()
254 check := func(event tui.Event, arg1 string, types ...actionType) {
255 if len(keymap[event]) != len(types) {
256 t.Errorf("invalid number of actions for %v (%d != %d)",
257 event, len(types), len(keymap[event]))
258 return
259 }
260 for idx, action := range keymap[event] {
261 if types[idx] != action.t {
262 t.Errorf("invalid action type (%d != %d)", types[idx], action.t)
263 }
264 }
265 if len(arg1) > 0 && keymap[event][0].a != arg1 {
266 t.Errorf("invalid action argument: (%s != %s)", arg1, keymap[event][0].a)
267 }
268 }
269 check(tui.CtrlA.AsEvent(), "", actBeginningOfLine)
270 parseKeymap(keymap,
271 "ctrl-a:kill-line,ctrl-b:toggle-sort+up+down,c:page-up,alt-z:page-down,"+
272 "f1:execute(ls {+})+abort+execute(echo \n{+})+select-all,f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+
273 "alt-a:execute-Multi@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};,"+
274 "x:Execute(foo+bar),X:execute/bar+baz/"+
275 ",f1:+first,f1:+top"+
276 ",,:abort,::accept,+:execute:++\nfoobar,Y:execute(baz)+up")
277 check(tui.CtrlA.AsEvent(), "", actKillLine)
278 check(tui.CtrlB.AsEvent(), "", actToggleSort, actUp, actDown)
279 check(tui.Key('c'), "", actPageUp)
280 check(tui.Key(','), "", actAbort)
281 check(tui.Key(':'), "", actAccept)
282 check(tui.AltKey('z'), "", actPageDown)
283 check(tui.F1.AsEvent(), "ls {+}", actExecute, actAbort, actExecute, actSelectAll, actFirst, actFirst)
284 check(tui.F2.AsEvent(), "echo {}, {}, {}", actExecute)
285 check(tui.F3.AsEvent(), "echo '({})'", actExecute)
286 check(tui.F4.AsEvent(), "less {}", actExecute)
287 check(tui.Key('x'), "foo+bar", actExecute)
288 check(tui.Key('X'), "bar+baz", actExecute)
289 check(tui.AltKey('a'), "echo (,),[,],/,:,;,%,{}", actExecuteMulti)
290 check(tui.AltKey('b'), "echo (,),[,],/,:,@,%,{}", actExecute)
291 check(tui.Key('+'), "++\nfoobar,Y:execute(baz)+up", actExecute)
292
293 for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ';', '/'} {
294 parseKeymap(keymap, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char))
295 check(tui.Key([]rune(fmt.Sprintf("%d", idx%10))[0]), "foobar", actExecute)
296 }
297
298 parseKeymap(keymap, "f1:abort")
299 check(tui.F1.AsEvent(), "", actAbort)
300}
301
302func TestParseEveryEvent(t *testing.T) {
303 pairs, _, err := parseKeyChords("every(2),every(0.5)", "")

Callers

nothing calls this directly

Calls 5

KeyFunction · 0.92
AltKeyFunction · 0.92
defaultKeymapFunction · 0.85
parseKeymapFunction · 0.85
AsEventMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…