1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
package modes
import (
"errors"
"testing"
"src.elv.sh/pkg/cli"
"src.elv.sh/pkg/cli/clitest"
"src.elv.sh/pkg/cli/tk"
"src.elv.sh/pkg/tt"
"src.elv.sh/pkg/ui"
)
var Args = tt.Args
func TestModeLine(t *testing.T) {
testModeLine(t, modeLine)
}
func TestModePrompt(t *testing.T) {
prompt := func(s string, b bool) ui.Text { return modePrompt(s, b)() }
testModeLine(t, tt.Fn(prompt).Named("prompt"))
}
func testModeLine(t *testing.T, fn any) {
tt.Test(t, fn,
Args("TEST", false).Rets(
ui.T("TEST", ui.Bold, ui.FgWhite, ui.BgMagenta)),
Args("TEST", true).Rets(
ui.Concat(
ui.T("TEST", ui.Bold, ui.FgWhite, ui.BgMagenta),
ui.T(" "))),
)
}
// Common test utilities.
var errMock = errors.New("mock error")
var withNonCodeAreaAddon = clitest.WithSpec(func(spec *cli.AppSpec) {
spec.State.Addons = []tk.Widget{tk.Label{}}
})
func startMode(app cli.App, w tk.Widget, err error) {
if w != nil {
app.PushAddon(w)
app.Redraw()
}
if err != nil {
app.Notify(ErrorText(err))
}
}
func testFocusedWidgetNotCodeArea(t *testing.T, fn func(cli.App) error) {
t.Helper()
f := clitest.Setup(withNonCodeAreaAddon)
defer f.Stop()
if err := fn(f.App); err != ErrFocusedWidgetNotCodeArea {
t.Errorf("should return ErrFocusedWidgetNotCodeArea, got %v", err)
}
}
|