github.com/elves/elvish@v0.15.0/pkg/cli/addons/stub/stub_test.go (about) 1 package stub 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/elves/elvish/pkg/cli" 8 . "github.com/elves/elvish/pkg/cli/clitest" 9 "github.com/elves/elvish/pkg/cli/term" 10 ) 11 12 func TestRendering(t *testing.T) { 13 f := Setup() 14 defer f.Stop() 15 16 Start(f.App, Config{Name: " STUB "}) 17 f.TestTTY(t, 18 "", term.DotHere, "\n", 19 " STUB ", Styles, 20 "******", 21 ) 22 } 23 24 func TestFocus(t *testing.T) { 25 f := Setup() 26 defer f.Stop() 27 28 Start(f.App, Config{Name: " STUB ", Focus: true}) 29 f.TestTTY(t, 30 "\n", 31 " STUB ", Styles, 32 "******", term.DotHere, 33 ) 34 } 35 36 func TestHandling(t *testing.T) { 37 f := Setup() 38 defer f.Stop() 39 40 bindingCalled := make(chan bool) 41 Start(f.App, Config{ 42 Binding: cli.MapHandler{term.K('a'): func() { bindingCalled <- true }}, 43 }) 44 45 f.TTY.Inject(term.K('a')) 46 select { 47 case <-bindingCalled: 48 // OK 49 case <-time.After(time.Second): 50 t.Errorf("Handler not called after 1s") 51 } 52 }