Skip to content
Myr

test: run model with provided input and check output

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Muehlhaeuser · committed by Christian Muehlhaeuser · parent 6bc35c7 · Browse files · 1 file+39 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+39 added−0 removed

  • other:+39 added−0 removed

1 file+39 added−0 removed

added:tea_test.go+39 added
1package tea23import (4 "bytes"5 "testing"6)78type testModel struct{}910func (m testModel) Init() Cmd {11 return nil12}1314func (m testModel) Update(msg Msg) (Model, Cmd) {15 switch msg.(type) {16 case KeyMsg:17 return m, Quit18 }19 return m, nil20}2122func (m testModel) View() string {23 return "success\n"24}2526func TestTeaModel(t *testing.T) {27 var buf bytes.Buffer28 var in bytes.Buffer29 in.Write([]byte("q"))3031 p := NewProgram(testModel{}, WithInput(&in), WithOutput(&buf))32 if err := p.Start(); err != nil {33 t.Fatal(err)34 }3536 if buf.Len() == 0 {37 t.Fatal("no output")38 }39}