github.com/kolbycrouch/elvish@v0.14.1-0.20210614162631-215b9ac1c423/pkg/cli/mode/mode_test.go (about)

     1  package mode
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"src.elv.sh/pkg/cli"
     8  	"src.elv.sh/pkg/cli/tk"
     9  	"src.elv.sh/pkg/tt"
    10  	"src.elv.sh/pkg/ui"
    11  )
    12  
    13  func TestModeLine(t *testing.T) {
    14  	testModeLine(t, tt.Fn("Line", modeLine))
    15  }
    16  
    17  func TestModePrompt(t *testing.T) {
    18  	testModeLine(t, tt.Fn("Prompt",
    19  		func(s string, b bool) ui.Text { return modePrompt(s, b)() }))
    20  }
    21  
    22  func testModeLine(t *testing.T, fn *tt.FnToTest) {
    23  	tt.Test(t, fn, tt.Table{
    24  		tt.Args("TEST", false).Rets(
    25  			ui.T("TEST", ui.Bold, ui.FgWhite, ui.BgMagenta)),
    26  		tt.Args("TEST", true).Rets(
    27  			ui.Concat(
    28  				ui.T("TEST", ui.Bold, ui.FgWhite, ui.BgMagenta),
    29  				ui.T(" "))),
    30  	})
    31  }
    32  
    33  // Common test utilities.
    34  
    35  var errMock = errors.New("mock error")
    36  
    37  func startMode(app cli.App, w tk.Widget, err error) {
    38  	if w != nil {
    39  		app.SetAddon(w, false)
    40  		app.Redraw()
    41  	}
    42  	if err != nil {
    43  		app.Notify(err.Error())
    44  	}
    45  }