github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/cli/clitest/apptest_test.go (about)

     1  package clitest
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/markusbkk/elvish/pkg/cli"
     7  	"github.com/markusbkk/elvish/pkg/cli/term"
     8  	"github.com/markusbkk/elvish/pkg/cli/tk"
     9  	"github.com/markusbkk/elvish/pkg/ui"
    10  )
    11  
    12  func TestFixture(t *testing.T) {
    13  	f := Setup(
    14  		WithSpec(func(spec *cli.AppSpec) {
    15  			spec.CodeAreaState.Buffer = tk.CodeBuffer{Content: "test", Dot: 4}
    16  		}),
    17  		WithTTY(func(tty TTYCtrl) {
    18  			tty.SetSize(20, 30) // h = 20, w = 30
    19  		}),
    20  	)
    21  	defer f.Stop()
    22  
    23  	// Verify that the functions passed to Setup have taken effect.
    24  	if f.App.ActiveWidget().(tk.CodeArea).CopyState().Buffer.Content != "test" {
    25  		t.Errorf("WithSpec did not work")
    26  	}
    27  
    28  	buf := f.MakeBuffer()
    29  	// Verify that the WithTTY function has taken effect.
    30  	if buf.Width != 30 {
    31  		t.Errorf("WithTTY did not work")
    32  	}
    33  
    34  	f.TestTTY(t, "test", term.DotHere)
    35  
    36  	f.App.Notify(ui.T("something"))
    37  	f.TestTTYNotes(t, "something")
    38  
    39  	f.App.CommitCode()
    40  	if code, err := f.Wait(); code != "test" || err != nil {
    41  		t.Errorf("Wait returned %q, %v", code, err)
    42  	}
    43  }