-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathparser_dcs_test.go
More file actions
116 lines (99 loc) · 2.71 KB
/
Copy pathparser_dcs_test.go
File metadata and controls
116 lines (99 loc) · 2.71 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package vte
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDcsMaxParams(t *testing.T) {
input := fmt.Sprintf("\x1bP%sp", strings.Repeat("1;", maxParams+1))
expected := testDcsHookSequence{
params: [][]uint16{
{1}, {1}, {1}, {1}, {1}, {1}, {1}, {1},
{1}, {1}, {1}, {1}, {1}, {1}, {1}, {1},
{1}, {1}, {1}, {1}, {1}, {1}, {1}, {1},
{1}, {1}, {1}, {1}, {1}, {1}, {1}, {1},
},
ignore: true,
}
dispatcher := &testDispatcher{}
parser := NewParser(dispatcher)
for _, b := range []byte(input) {
parser.Advance(b)
}
assert.Equal(t, 1, len(dispatcher.dispatched))
assert.Equal(t, expected.ignore, dispatcher.dispatched[0].(testDcsHookSequence).ignore)
assert.Equal(t, maxParams, len(dispatcher.dispatched[0].(testDcsHookSequence).params))
assert.Equal(t, expected.params, dispatcher.dispatched[0].(testDcsHookSequence).params)
}
func TestDcsReset(t *testing.T) {
input := "\x1b[3;1\x1bP1$tx\x9c"
expected := []testSequence{
testDcsHookSequence{
params: [][]uint16{{1}},
intermediates: []byte{'$'},
rune: 't',
ignore: false,
},
testDcsPutSequence('x'),
testDcsUnhookSequence{},
}
dispatcher := &testDispatcher{}
parser := NewParser(dispatcher)
for _, b := range []byte(input) {
parser.Advance(b)
}
assert.Equal(t, 3, len(dispatcher.dispatched))
assert.Equal(t, expected, dispatcher.dispatched)
}
func TestDcsParse(t *testing.T) {
input := "\x1bP0;1|17/ab\x9c"
expected := []testSequence{
testDcsHookSequence{
params: [][]uint16{{0}, {1}},
rune: '|',
intermediates: []byte{},
ignore: false,
},
testDcsPutSequence('1'),
testDcsPutSequence('7'),
testDcsPutSequence('/'),
testDcsPutSequence('a'),
testDcsPutSequence('b'),
testDcsUnhookSequence{},
}
dispatcher := &testDispatcher{}
parser := NewParser(dispatcher)
for _, b := range []byte(input) {
parser.Advance(b)
}
assert.Equal(t, len(expected), len(dispatcher.dispatched))
assert.Equal(t, expected, dispatcher.dispatched)
}
func TestDcsIntermediateResetOnExit(t *testing.T) {
input := "\x1bP=1sZZZ\x1b+\x5c"
expected := []testSequence{
testDcsHookSequence{
params: [][]uint16{{1}},
intermediates: []byte{'='},
rune: 's',
ignore: false,
},
testDcsPutSequence('Z'),
testDcsPutSequence('Z'),
testDcsPutSequence('Z'),
testDcsUnhookSequence{},
testEscSequence{
intermediates: []byte{'+'},
b: 0x5c,
ignore: false,
},
}
dispatcher := &testDispatcher{}
parser := NewParser(dispatcher)
for _, b := range []byte(input) {
parser.Advance(b)
}
assert.Equal(t, len(expected), len(dispatcher.dispatched))
assert.Equal(t, expected, dispatcher.dispatched)
}