2022-10-08 22:04:26 -04:00
|
|
|
package tea
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestClearMsg(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
cmds sequenceMsg
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "clear_screen",
|
|
|
|
cmds: []Cmd{ClearScreen},
|
2023-12-04 11:50:59 -05:00
|
|
|
expected: "\x1b[?25l\x1b[2J\x1b[1;1H\x1b[1;1Hsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",
|
2022-10-08 22:04:26 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "altscreen",
|
|
|
|
cmds: []Cmd{EnterAltScreen, ExitAltScreen},
|
2023-12-04 11:50:59 -05:00
|
|
|
expected: "\x1b[?25l\x1b[?1049h\x1b[2J\x1b[1;1H\x1b[1;1H\x1b[?25l\x1b[?1049l\x1b[?25lsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",
|
2022-10-08 22:04:26 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "altscreen_autoexit",
|
|
|
|
cmds: []Cmd{EnterAltScreen},
|
2023-12-04 11:50:59 -05:00
|
|
|
expected: "\x1b[?25l\x1b[?1049h\x1b[2J\x1b[1;1H\x1b[1;1H\x1b[?25lsuccess\r\n\x1b[2;0H\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?1049l\x1b[?25h",
|
2022-10-08 22:04:26 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mouse_cellmotion",
|
|
|
|
cmds: []Cmd{EnableMouseCellMotion},
|
2023-12-04 11:50:59 -05:00
|
|
|
expected: "\x1b[?25l\x1b[?1002h\x1b[?1006hsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",
|
2022-10-08 22:04:26 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mouse_allmotion",
|
|
|
|
cmds: []Cmd{EnableMouseAllMotion},
|
2023-12-04 11:50:59 -05:00
|
|
|
expected: "\x1b[?25l\x1b[?1003h\x1b[?1006hsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",
|
2022-10-08 22:04:26 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mouse_disable",
|
|
|
|
cmds: []Cmd{EnableMouseAllMotion, DisableMouse},
|
2023-12-04 11:50:59 -05:00
|
|
|
expected: "\x1b[?25l\x1b[?1003h\x1b[?1006h\x1b[?1002l\x1b[?1003l\x1b[?1006lsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",
|
2022-10-08 22:04:26 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "cursor_hide",
|
|
|
|
cmds: []Cmd{HideCursor},
|
2023-12-04 11:50:59 -05:00
|
|
|
expected: "\x1b[?25l\x1b[?25lsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",
|
2022-10-08 22:04:26 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "cursor_hideshow",
|
|
|
|
cmds: []Cmd{HideCursor, ShowCursor},
|
2023-12-04 11:50:59 -05:00
|
|
|
expected: "\x1b[?25l\x1b[?25l\x1b[?25hsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1006l",
|
2022-10-08 22:04:26 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
var in bytes.Buffer
|
|
|
|
|
|
|
|
m := &testModel{}
|
|
|
|
p := NewProgram(m, WithInput(&in), WithOutput(&buf))
|
|
|
|
|
|
|
|
test.cmds = append(test.cmds, Quit)
|
|
|
|
go p.Send(test.cmds)
|
|
|
|
|
|
|
|
if _, err := p.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf.String() != test.expected {
|
|
|
|
t.Errorf("expected embedded sequence, got %q", buf.String())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|