-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputhandler_dcs_test.go
More file actions
225 lines (208 loc) · 6.52 KB
/
inputhandler_dcs_test.go
File metadata and controls
225 lines (208 loc) · 6.52 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package xterm
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestRequestStatusString(t *testing.T) {
t.Parallel()
type Expectation struct {
Response string
}
t.Run("DECSCA_unprotected", func(t *testing.T) {
t.Parallel()
h := newTestInputHandler(80, 24)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
// Query DECSCA — default is unprotected (0)
h.ParseString("\x1bP$q\"q\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP1$r0\"q\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
t.Run("DECSCA_protected", func(t *testing.T) {
t.Parallel()
h := newTestInputHandler(80, 24)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
// Enable protected mode via DECSCA (CSI 1 " q), then query
h.ParseString("\x1b[1\"q")
h.ParseString("\x1bP$q\"q\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP1$r1\"q\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
t.Run("DECSCL_conformance_level", func(t *testing.T) {
t.Parallel()
h := newTestInputHandler(80, 24)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
h.ParseString("\x1bP$q\"p\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP1$r61;1\"p\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
t.Run("DECSTBM_default_scroll_region", func(t *testing.T) {
t.Parallel()
h := newTestInputHandler(80, 24)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
// Default scroll region is full screen: 1;24
h.ParseString("\x1bP$qr\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP1$r1;24r\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
t.Run("DECSTBM_custom_scroll_region", func(t *testing.T) {
t.Parallel()
h := newTestInputHandler(80, 24)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
// Set scroll region to lines 5-20, then query
h.ParseString("\x1b[5;20r")
h.ParseString("\x1bP$qr\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP1$r5;20r\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
t.Run("SGR_default", func(t *testing.T) {
t.Parallel()
h := newTestInputHandler(80, 24)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
h.ParseString("\x1bP$qm\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP1$r0m\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
t.Run("DECSCUSR_default_cursor_style", func(t *testing.T) {
t.Parallel()
h := newTestInputHandler(80, 24)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
// Default: block, no blink → style 2
h.ParseString("\x1bP$q q\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP1$r2 q\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
t.Run("DECSCUSR_blinking_block", func(t *testing.T) {
t.Parallel()
opts := DefaultOptions()
opts.Cols = 80
opts.Rows = 24
opts.CursorBlink = true
opts.CursorStyle = CursorStyleBlock
optsSvc := NewOptionsService(&opts)
bufSvc := NewBufferService(optsSvc)
charSvc := NewCharsetService()
coreSvc := NewCoreService(optsSvc)
oscLinkSvc := NewOscLinkService(bufSvc)
uniSvc := NewUnicodeService()
h := NewInputHandler(bufSvc, charSvc, coreSvc, optsSvc, oscLinkSvc, uniSvc)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
// Blinking block → style 1
h.ParseString("\x1bP$q q\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP1$r1 q\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
t.Run("DECSCUSR_underline_no_blink", func(t *testing.T) {
t.Parallel()
opts := DefaultOptions()
opts.Cols = 80
opts.Rows = 24
opts.CursorStyle = CursorStyleUnderline
optsSvc := NewOptionsService(&opts)
bufSvc := NewBufferService(optsSvc)
charSvc := NewCharsetService()
coreSvc := NewCoreService(optsSvc)
oscLinkSvc := NewOscLinkService(bufSvc)
uniSvc := NewUnicodeService()
h := NewInputHandler(bufSvc, charSvc, coreSvc, optsSvc, oscLinkSvc, uniSvc)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
// Underline, no blink → style 4
h.ParseString("\x1bP$q q\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP1$r4 q\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
t.Run("DECSCUSR_bar_blinking", func(t *testing.T) {
t.Parallel()
opts := DefaultOptions()
opts.Cols = 80
opts.Rows = 24
opts.CursorBlink = true
opts.CursorStyle = CursorStyleBar
optsSvc := NewOptionsService(&opts)
bufSvc := NewBufferService(optsSvc)
charSvc := NewCharsetService()
coreSvc := NewCoreService(optsSvc)
oscLinkSvc := NewOscLinkService(bufSvc)
uniSvc := NewUnicodeService()
h := NewInputHandler(bufSvc, charSvc, coreSvc, optsSvc, oscLinkSvc, uniSvc)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
// Bar, blinking → style 5
h.ParseString("\x1bP$q q\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP1$r5 q\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
t.Run("unknown_request", func(t *testing.T) {
t.Parallel()
h := newTestInputHandler(80, 24)
var response string
h.coreService.OnDataEmitter.Event(func(data string) {
response = data
})
// Unknown request string
h.ParseString("\x1bP$qz\x1b\\")
got := Expectation{Response: response}
expected := Expectation{Response: "\x1bP0$r\x1b\\"}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
}