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
|
package vt100
import (
"io"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestScan(t *testing.T) {
nextCase:
for _, testCase := range []struct {
in string
want []Command
}{
{"fÜ", []Command{
runeCommand('f'),
runeCommand('Ü'),
}},
{"\u001babc", []Command{
escapeCommand{'a', ""},
runeCommand('b'),
runeCommand('c'),
}},
{"\u001b[123;31d", []Command{escapeCommand{'d', "123;31"}}},
{"\u009b123;31d", []Command{escapeCommand{'d', "123;31"}}},
{"\u001b123", []Command{
escapeCommand{'1', ""},
runeCommand('2'),
runeCommand('3'),
}},
{"\u001b[12;\"asd\"s", []Command{
escapeCommand{'s', `12;"asd"`},
}},
} {
s := strings.NewReader(testCase.in)
for i := 0; i < len(testCase.want); i++ {
got, err := Decode(s)
if err == io.EOF {
t.Error("unexpected eof")
continue nextCase
}
if !assert.Nil(t, err, "unexpected error") {
continue
}
assert.Equal(t, testCase.want[i], got)
}
_, err := Decode(s)
assert.Equal(t, err, io.EOF)
}
}
|