This repository was archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathhterm_vt_character_map_tests.js
245 lines (202 loc) · 6.59 KB
/
hterm_vt_character_map_tests.js
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @fileoverview Unit tests for hterm.VT.CharacterMap and friends.
*/
describe('hterm_vt_character_map_tests.js', () => {
/**
* Verify null maps work sanely.
*/
it('null-map', () => {
const map = new hterm.VT.CharacterMap('foo', null);
assert.equal(map.description, 'foo');
assert.isNull(map.GL);
});
/**
* Verify empty maps work sanely.
*/
it('empty-map', () => {
const map = new hterm.VT.CharacterMap('foo bar', {});
assert.equal(map.description, 'foo bar');
assert.equal(typeof map.GL, 'function');
});
/**
* Verify GL map works.
*/
it('gl-translate', () => {
const map = new hterm.VT.CharacterMap('test', {'a': 'b'});
assert.equal(map.GL('a'), 'b');
assert.equal(map.GL('b'), 'b');
assert.equal(map.GL('c'), 'c');
});
/**
* Verify handling of overrides.
*/
it('overrides', () => {
const map = new hterm.VT.CharacterMap('test', {'a': 'A', 'b': 'B'});
// Verify things start off sane.
assert.equal(map.GL('a'), 'A');
assert.equal(map.GL('b'), 'B');
assert.equal(map.GL('c'), 'c');
assert.equal(map.GL('d'), 'd');
// The override will update existing mappings.
map.setOverrides({'a': 'A', 'c': 'C'});
assert.equal(map.GL('a'), 'A');
assert.equal(map.GL('b'), 'B');
assert.equal(map.GL('c'), 'C');
assert.equal(map.GL('d'), 'd');
// Do the same thing again!
map.setOverrides({'a': 'Z', 'd': 'D'});
assert.equal(map.GL('a'), 'Z');
assert.equal(map.GL('b'), 'B');
assert.equal(map.GL('c'), 'c');
assert.equal(map.GL('d'), 'D');
});
/**
* Verify handling of resets.
*/
it('resets', () => {
const map = new hterm.VT.CharacterMap('test', {'a': 'A', 'b': 'B'});
// Verify things start off sane.
assert.equal(map.GL('a'), 'A');
assert.equal(map.GL('b'), 'B');
assert.equal(map.GL('c'), 'c');
assert.strictEqual(map.glmap_, map.glmapBase_);
// The override will generate a new internal mapping.
map.setOverrides({'a': 'A', 'c': 'C'});
assert.equal(map.GL('a'), 'A');
assert.equal(map.GL('b'), 'B');
assert.equal(map.GL('c'), 'C');
assert.notStrictEqual(map.glmap_, map.glmapBase_);
// Resetting will get the old mapping, and object state.
map.reset();
assert.equal(map.GL('a'), 'A');
assert.equal(map.GL('b'), 'B');
assert.equal(map.GL('c'), 'c');
assert.strictEqual(map.glmap_, map.glmapBase_);
});
/**
* Verify map clones work.
*/
it('clone', () => {
const map = new hterm.VT.CharacterMap('test', {'a': 'A', 'b': 'B'});
const dup = map.clone();
// Make sure the dupe behaves the same, but isn't the same.
assert.equal(map.description, dup.description);
assert.equal(map.GL('a'), 'A');
assert.equal(dup.GL('a'), 'A');
dup.setOverrides({'b': 'C', 'x': 'X'});
assert.equal(map.GL('b'), 'B');
assert.equal(dup.GL('b'), 'C');
assert.equal(map.GL('x'), 'x');
assert.equal(dup.GL('X'), 'X');
});
/**
* Verify basic character map handling.
*/
it('basic', () => {
const maps = new hterm.VT.CharacterMaps();
// The default mapping should pass through to the default table.
assert.strictEqual(maps.maps_, maps.mapsBase_);
assert.strictEqual(maps.maps_, hterm.VT.CharacterMaps.DefaultMaps);
// Reset works.
maps.reset();
assert.strictEqual(maps.maps_, maps.mapsBase_);
assert.strictEqual(maps.maps_, hterm.VT.CharacterMaps.DefaultMaps);
});
/**
* Verify getMap works.
*/
it('getMap', () => {
const maps = new hterm.VT.CharacterMaps();
assert.isUndefined(maps.getMap('X'));
assert.isDefined(maps.getMap('0'));
assert.strictEqual(maps.getMap('0'), hterm.VT.CharacterMaps.DefaultMaps['0']);
});
/**
* Verify adding a new mapping doesn't mess with the default table.
*/
it('new-map', () => {
const maps = new hterm.VT.CharacterMaps();
const map = new hterm.VT.CharacterMap('test', {});
// Add a new map to the table.
assert.isUndefined(maps.getMap('X'));
maps.addMap('X', map);
assert.strictEqual(maps.getMap('X'), map);
assert.isUndefined(hterm.VT.CharacterMaps.DefaultMaps['X']);
// The mapping table should be updated now.
assert.notStrictEqual(maps.maps_, maps.mapsBase_);
assert.notStrictEqual(maps.maps_, hterm.VT.CharacterMaps.DefaultMaps);
// Reset works.
maps.reset();
assert.strictEqual(maps.maps_, maps.mapsBase_);
assert.strictEqual(maps.maps_, hterm.VT.CharacterMaps.DefaultMaps);
});
/**
* Verify updating an existing mapping doesn't mess with the default table.
*/
it('update-map', () => {
const maps = new hterm.VT.CharacterMaps();
const map = new hterm.VT.CharacterMap('test', {});
// Update a mapping in the table.
assert.isDefined(maps.getMap('0'));
maps.addMap('0', map);
assert.strictEqual(maps.getMap('0'), map);
assert.notStrictEqual(hterm.VT.CharacterMaps.DefaultMaps['0'], map);
// The mapping table should be updated now.
assert.notStrictEqual(maps.maps_, maps.mapsBase_);
assert.notStrictEqual(maps.maps_, hterm.VT.CharacterMaps.DefaultMaps);
// Reset works.
maps.reset();
assert.strictEqual(maps.maps_, maps.mapsBase_);
assert.strictEqual(maps.maps_, hterm.VT.CharacterMaps.DefaultMaps);
});
/**
* Verify setting overrides work.
*/
it('overrides', () => {
const maps = new hterm.VT.CharacterMaps();
let map;
// Check the default mappings.
assert.isUndefined(maps.getMap('U'));
assert.isUndefined(maps.getMap('V'));
assert.isUndefined(maps.getMap('X'));
assert.isDefined(maps.getMap('0'));
// Update some maps and check the results.
maps.setOverrides({
'U': null,
'V': {},
'X': {'a': 'A'},
'0': {'a': 'A'},
});
map = maps.getMap('U');
assert.isDefined(map);
assert.isNull(map.GL);
map = maps.getMap('V');
assert.isDefined(map);
assert.equal(map.GL('a'), 'a');
map = maps.getMap('X');
assert.isDefined(map);
assert.equal(map.GL('a'), 'A');
map = maps.getMap('0');
assert.isDefined(map);
assert.equal(map.GL('a'), 'A');
assert.equal(map.GL('\x60'), '\u25c6');
// Now verify the default maps are sane.
assert.isUndefined(hterm.VT.CharacterMaps.DefaultMaps['U']);
assert.isUndefined(hterm.VT.CharacterMaps.DefaultMaps['V']);
assert.isUndefined(hterm.VT.CharacterMaps.DefaultMaps['X']);
assert.isDefined(hterm.VT.CharacterMaps.DefaultMaps['0']);
assert.notStrictEqual(
hterm.VT.CharacterMaps.DefaultMaps['0'], maps.getMap('0'));
// Now reset the things back.
maps.reset();
assert.isUndefined(maps.getMap('U'));
assert.isUndefined(maps.getMap('V'));
assert.isUndefined(maps.getMap('X'));
assert.isDefined(maps.getMap('0'));
assert.strictEqual(hterm.VT.CharacterMaps.DefaultMaps['0'], maps.getMap('0'));
});
});