mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-07-02 03:34:29 +02:00
sshd/terminal: Import test from upstream patch
This commit is contained in:
parent
91c6e55432
commit
c9b58a80fa
@ -59,6 +59,7 @@ func TestClose(t *testing.T) {
|
|||||||
var keyPressTests = []struct {
|
var keyPressTests = []struct {
|
||||||
in string
|
in string
|
||||||
line string
|
line string
|
||||||
|
received string
|
||||||
err error
|
err error
|
||||||
throwAwayLines int
|
throwAwayLines int
|
||||||
}{
|
}{
|
||||||
@ -237,6 +238,49 @@ func TestKeyPresses(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var renderTests = []struct {
|
||||||
|
in string
|
||||||
|
received string
|
||||||
|
err error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
// Cursor move after keyHome (left 4) then enter (right 4, newline)
|
||||||
|
in: "abcd\x1b[H\r",
|
||||||
|
received: "> abcd\x1b[4D\x1b[4C\r\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Write, home, prepend, enter. Prepends rewrites the line.
|
||||||
|
in: "cdef\x1b[Hab\r",
|
||||||
|
received: "> cdef" + // Initial input
|
||||||
|
"\x1b[4Da" + // Move cursor back, insert first char
|
||||||
|
"cdef" + // Copy over original string
|
||||||
|
"\x1b[4Dbcdef" + // Repeat for second char with copy
|
||||||
|
"\x1b[4D" + // Put cursor back in position to insert again
|
||||||
|
"\x1b[4C\r\n", // Put cursor at the end of the line and newline.
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRender(t *testing.T) {
|
||||||
|
for i, test := range renderTests {
|
||||||
|
for j := 1; j < len(test.in); j++ {
|
||||||
|
c := &MockTerminal{
|
||||||
|
toSend: []byte(test.in),
|
||||||
|
bytesPerRead: j,
|
||||||
|
}
|
||||||
|
ss := NewTerminal(c, "> ")
|
||||||
|
_, err := ss.ReadLine()
|
||||||
|
if err != test.err {
|
||||||
|
t.Errorf("Error resulting from test %d (%d bytes per read) was '%v', expected '%v'", i, j, err, test.err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if test.received != string(c.received) {
|
||||||
|
t.Errorf("Results rendered from test %d (%d bytes per read) was '%s', expected '%s'", i, j, c.received, test.received)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPasswordNotSaved(t *testing.T) {
|
func TestPasswordNotSaved(t *testing.T) {
|
||||||
c := &MockTerminal{
|
c := &MockTerminal{
|
||||||
toSend: []byte("password\r\x1b[A\r"),
|
toSend: []byte("password\r\x1b[A\r"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user