fix(key): support very long buffered input (#570)

This commit is contained in:
Raphael 'kena' Poss
2023-10-18 12:59:26 +02:00
committed by GitHub
parent 6d07f4a410
commit 5536bca34e
2 changed files with 54 additions and 3 deletions

View File

@@ -200,7 +200,7 @@ func TestDetectOneMsg(t *testing.T) {
for _, tc := range td {
t.Run(fmt.Sprintf("%q", string(tc.seq)), func(t *testing.T) {
width, msg := detectOneMsg(tc.seq)
width, msg := detectOneMsg(tc.seq, false /* canHaveMoreData */)
if width != len(tc.seq) {
t.Errorf("parser did not consume the entire input: got %d, expected %d", width, len(tc.seq))
}
@@ -211,6 +211,25 @@ func TestDetectOneMsg(t *testing.T) {
}
}
func TestReadLongInput(t *testing.T) {
input := strings.Repeat("a", 1000)
msgs := testReadInputs(t, bytes.NewReader([]byte(input)))
if len(msgs) != 1 {
t.Errorf("expected 1 messages, got %d", len(msgs))
}
km := msgs[0]
k := Key(km.(KeyMsg))
if k.Type != KeyRunes {
t.Errorf("expected key runes, got %d", k.Type)
}
if len(k.Runes) != 1000 || !reflect.DeepEqual(k.Runes, []rune(input)) {
t.Errorf("unexpected runes: %+v", k)
}
if k.Alt {
t.Errorf("unexpected alt")
}
}
func TestReadInput(t *testing.T) {
type test struct {
keyname string