(t *testing.T)
| 250 | } |
| 251 | |
| 252 | func 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 | |
| 302 | func TestParseEveryEvent(t *testing.T) { |
| 303 | pairs, _, err := parseKeyChords("every(2),every(0.5)", "") |
nothing calls this directly
no test coverage detected
searching dependent graphs…