Skip to content

Commit 95f332c

Browse files
authored
Merge pull request #4699 from Tyriar/slow_tests
Improve slow tests
2 parents 0667c7a + 1c5596d commit 95f332c

File tree

4 files changed

+62
-58
lines changed

4 files changed

+62
-58
lines changed

addons/xterm-addon-image/src/base64.test.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ describe('Base64Decoder', () => {
4545
assert.deepEqual(dec.data8, inp);
4646
}
4747
});
48-
it('1+2 bytes', function() {
49-
this.timeout(20000);
50-
const dec = new Base64Decoder(0);
51-
for (let a = 0; a < 256; ++a) {
48+
for (let a = 0; a < 256; ++a) {
49+
it(`1+2 bytes (${a})`, function() {
50+
const dec = new Base64Decoder(0);
5251
for (let b = 0; b < 256; ++b) {
5352
dec.init(2);
5453
const inp = new Uint8Array([a, b]);
@@ -57,12 +56,11 @@ describe('Base64Decoder', () => {
5756
assert.strictEqual(dec.end(), 0);
5857
assert.deepEqual(dec.data8, inp);
5958
}
60-
}
61-
});
62-
it('2+3 bytes', function() {
63-
this.timeout(20000);
64-
const dec = new Base64Decoder(0);
65-
for (let a = 0; a < 256; ++a) {
59+
});
60+
}
61+
for (let a = 0; a < 256; ++a) {
62+
it(`2+3 bytes (${a})`, function() {
63+
const dec = new Base64Decoder(0);
6664
for (let b = 0; b < 256; ++b) {
6765
dec.init(3);
6866
const inp = new Uint8Array([0, a, b]);
@@ -71,12 +69,11 @@ describe('Base64Decoder', () => {
7169
assert.strictEqual(dec.end(), 0);
7270
assert.deepEqual(dec.data8, inp);
7371
}
74-
}
75-
});
76-
it('3+4 bytes', function() {
77-
this.timeout(20000);
78-
const dec = new Base64Decoder(0);
79-
for (let a = 0; a < 256; ++a) {
72+
});
73+
}
74+
for (let a = 0; a < 256; ++a) {
75+
it(`3+4 bytes (${a})`, function() {
76+
const dec = new Base64Decoder(0);
8077
for (let b = 0; b < 256; ++b) {
8178
dec.init(4);
8279
const inp = new Uint8Array([0, 0, a, b]);
@@ -85,8 +82,8 @@ describe('Base64Decoder', () => {
8582
assert.strictEqual(dec.end(), 0);
8683
assert.deepEqual(dec.data8, inp);
8784
}
88-
}
89-
});
85+
});
86+
}
9087
it('padding', () => {
9188
const dec = new Base64Decoder(0);
9289
const d = fromBs('Hello, here comes the mouse');

src/common/input/TextDecoder.test.ts

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ function fromByteString(s: string): Uint8Array {
2929
return result;
3030
}
3131

32+
const BATCH_SIZE = 2048;
33+
3234
const TEST_STRINGS = [
3335
'Лорем ипсум долор сит амет, ех сеа аццусам диссентиет. Ан еос стет еирмод витуперата. Иус дицерет урбанитас ет. Ан при алтера долорес сплендиде, цу яуо интегре денияуе, игнота волуптариа инструцтиор цу вим.',
3436
'ლორემ იფსუმ დოლორ სით ამეთ, ფაცერ მუციუს ცონსეთეთურ ყუო იდ, ფერ ვივენდუმ ყუაერენდუმ ეა, ესთ ამეთ მოვეთ სუავითათე ცუ. ვითაე სენსიბუს ან ვიხ. ეხერცი დეთერრუისსეთ უთ ყუი. ვოცენთ დებითის ადიფისცი ეთ ფერ. ნეც ან ფეუგაით ფორენსიბუს ინთერესსეთ. იდ დიცო რიდენს იუს. დისსენთიეთ ცონსეყუუნთურ სედ ნე, ნოვუმ მუნერე ეუმ ათ, ნე ეუმ ნიჰილ ირაცუნდია ურბანითას.',
@@ -54,36 +56,40 @@ describe('text encodings', () => {
5456

5557
describe('StringToUtf32 decoder', () => {
5658
describe('full codepoint test', () => {
57-
it('0..65535', () => {
58-
const decoder = new StringToUtf32();
59-
const target = new Uint32Array(5);
60-
for (let i = 0; i < 65536; ++i) {
61-
// skip surrogate pairs and a BOM
62-
if ((i >= 0xD800 && i <= 0xDFFF) || i === 0xFEFF) {
63-
continue;
59+
for (let min = 0; min < 65535; min += BATCH_SIZE) {
60+
const max = Math.min(min + BATCH_SIZE, 65536);
61+
it(`${formatRange(min, max)}`, () => {
62+
const decoder = new StringToUtf32();
63+
const target = new Uint32Array(5);
64+
for (let i = min; i < max; ++i) {
65+
// skip surrogate pairs and a BOM
66+
if ((i >= 0xD800 && i <= 0xDFFF) || i === 0xFEFF) {
67+
continue;
68+
}
69+
const length = decoder.decode(String.fromCharCode(i), target);
70+
assert.equal(length, 1);
71+
assert.equal(target[0], i);
72+
assert.equal(utf32ToString(target, 0, length), String.fromCharCode(i));
73+
decoder.clear();
6474
}
65-
const length = decoder.decode(String.fromCharCode(i), target);
66-
assert.equal(length, 1);
67-
assert.equal(target[0], i);
68-
assert.equal(utf32ToString(target, 0, length), String.fromCharCode(i));
69-
decoder.clear();
70-
}
71-
});
72-
73-
it('65536..0x10FFFF (surrogates)', function (): void {
74-
this.timeout(20000);
75-
const decoder = new StringToUtf32();
76-
const target = new Uint32Array(5);
77-
for (let i = 65536; i < 0x10FFFF; ++i) {
78-
const codePoint = i - 0x10000;
79-
const s = String.fromCharCode((codePoint >> 10) + 0xD800) + String.fromCharCode((codePoint % 0x400) + 0xDC00);
80-
const length = decoder.decode(s, target);
81-
assert.equal(length, 1);
82-
assert.equal(target[0], i);
83-
assert.equal(utf32ToString(target, 0, length), s);
84-
decoder.clear();
85-
}
86-
});
75+
});
76+
}
77+
for (let min = 65536; min < 0x10FFFF; min += BATCH_SIZE) {
78+
const max = Math.min(min + BATCH_SIZE, 0x10FFFF);
79+
it(`${formatRange(min, max)} (surrogates)`, () => {
80+
const decoder = new StringToUtf32();
81+
const target = new Uint32Array(5);
82+
for (let i = min; i < max; ++i) {
83+
const codePoint = i - 0x10000;
84+
const s = String.fromCharCode((codePoint >> 10) + 0xD800) + String.fromCharCode((codePoint % 0x400) + 0xDC00);
85+
const length = decoder.decode(s, target);
86+
assert.equal(length, 1);
87+
assert.equal(target[0], i);
88+
assert.equal(utf32ToString(target, 0, length), s);
89+
decoder.clear();
90+
}
91+
});
92+
}
8793

8894
it('0xFEFF(BOM)', () => {
8995
const decoder = new StringToUtf32();
@@ -121,11 +127,8 @@ describe('text encodings', () => {
121127

122128
describe('Utf8ToUtf32 decoder', () => {
123129
describe('full codepoint test', () => {
124-
function formatRange(min: number, max: number): string {
125-
return `${min}..${max} (0x${min.toString(16).toUpperCase()}..0x${max.toString(16).toUpperCase()})`;
126-
}
127-
for (let min = 0; min < 65535; min += 10000) {
128-
const max = Math.min(min + 10000, 65536);
130+
for (let min = 0; min < 65535; min += BATCH_SIZE) {
131+
const max = Math.min(min + BATCH_SIZE, 65536);
129132
it(`${formatRange(min, max)} (1/2/3 byte sequences)`, () => {
130133
const decoder = new Utf8ToUtf32();
131134
const target = new Uint32Array(5);
@@ -142,9 +145,9 @@ describe('text encodings', () => {
142145
}
143146
});
144147
}
145-
for (let minRaw = 60000; minRaw < 0x10FFFF; minRaw += 10000) {
148+
for (let minRaw = 60000; minRaw < 0x10FFFF; minRaw += BATCH_SIZE) {
146149
const min = Math.max(minRaw, 65536);
147-
const max = Math.min(minRaw + 10000, 0x10FFFF);
150+
const max = Math.min(minRaw + BATCH_SIZE, 0x10FFFF);
148151
it(`${formatRange(min, max)} (4 byte sequences)`, function (): void {
149152
const decoder = new Utf8ToUtf32();
150153
const target = new Uint32Array(5);
@@ -265,3 +268,7 @@ describe('text encodings', () => {
265268
});
266269
});
267270
});
271+
272+
function formatRange(min: number, max: number): string {
273+
return `${min}..${max} (0x${min.toString(16).toUpperCase()}..0x${max.toString(16).toUpperCase()})`;
274+
}

src/common/parser/DcsParser.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ describe('DcsParser', () => {
227227
assert.deepEqual(reports, [['two', [1, 2, 3], 'Here comes the mouse!'], ['one', [1, 2, 3], 'Here comes the mouse!']]);
228228
});
229229
it('should work up to payload limit', function(): void {
230-
this.timeout(10000);
230+
this.timeout(30000);
231231
parser.registerHandler(identifier({intermediates: '+', final: 'p'}), new DcsHandler((data, params) => { reports.push([params.toArray(), data]); return true; }));
232232
parser.hook(identifier({intermediates: '+', final: 'p'}), Params.fromArray([1, 2, 3]));
233233
const data = toUtf32('A'.repeat(1000));
@@ -238,7 +238,7 @@ describe('DcsParser', () => {
238238
assert.deepEqual(reports, [[[1, 2, 3], 'A'.repeat(PAYLOAD_LIMIT)]]);
239239
});
240240
it('should abort for payload limit +1', function(): void {
241-
this.timeout(10000);
241+
this.timeout(30000);
242242
parser.registerHandler(identifier({intermediates: '+', final: 'p'}), new DcsHandler((data, params) => { reports.push([params.toArray(), data]); return true; }));
243243
parser.hook(identifier({intermediates: '+', final: 'p'}), Params.fromArray([1, 2, 3]));
244244
let data = toUtf32('A'.repeat(1000));

src/common/parser/OscParser.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ describe('OscParser', () => {
221221
assert.deepEqual(reports, [['two', 'Here comes the mouse!'], ['one', 'Here comes the mouse!']]);
222222
});
223223
it('should work up to payload limit', function(): void {
224-
this.timeout(10000);
224+
this.timeout(30000);
225225
parser.registerHandler(1234, new OscHandler(data => { reports.push([1234, data]); return true; }));
226226
parser.start();
227227
let data = toUtf32('1234;');
@@ -234,7 +234,7 @@ describe('OscParser', () => {
234234
assert.deepEqual(reports, [[1234, 'A'.repeat(PAYLOAD_LIMIT)]]);
235235
});
236236
it('should abort for payload limit +1', function(): void {
237-
this.timeout(10000);
237+
this.timeout(30000);
238238
parser.registerHandler(1234, new OscHandler(data => { reports.push([1234, data]); return true; }));
239239
parser.start();
240240
let data = toUtf32('1234;');

0 commit comments

Comments
 (0)