Skip to content

Commit b2eff5a

Browse files
committed
merge resize tests for PNG & QOI into one block
1 parent 31c53bc commit b2eff5a

1 file changed

Lines changed: 33 additions & 63 deletions

File tree

addons/addon-image/test/ImageAddon.test.ts

Lines changed: 33 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -313,49 +313,7 @@ test.describe('ImageAddon', () => {
313313
});
314314
});
315315

316-
test.describe('IIP - resizing', () => {
317-
/**
318-
* The correct resize behavior is wonky and needs to be tested against iTerm2,
319-
* especially for missing params to derive correct default behavior.
320-
* We document the current behavior here w'o claiming to be fully in line with iTerm2.
321-
* ref: https://iterm2.com/documentation-images.html
322-
* imgcat: https://iterm2.com/utilities/imgcat
323-
*/
324-
test('palette.png: N --> width=20 height=5 preserveAspectRatio=0', async () => {
325-
// cell based resize
326-
const header = 'size=525;width=20;height=5;preserveAspectRatio=0';
327-
await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_PNG_BASE64}\x07`);
328-
const dim = await getDimensions();
329-
deepStrictEqual(await getOrigSize(1), [dim.cellWidth * 20, dim.cellHeight * 5]);
330-
});
331-
test('palette.png: Npx --> width=320px height=160px preserveAspectRatio=0', async () => {
332-
// pixel based resize
333-
const header = 'size=525;width=320px;height=160px;preserveAspectRatio=0';
334-
await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_PNG_BASE64}\x07`);
335-
deepStrictEqual(await getOrigSize(1), [320, 160]);
336-
});
337-
test('palette.png: N% --> width=50% height=30% preserveAspectRatio=0', async () => {
338-
// % of viewport resize
339-
const header = 'size=525;width=50%;height=30%;preserveAspectRatio=0';
340-
await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_PNG_BASE64}\x07`);
341-
const dim = await getDimensions();
342-
deepStrictEqual(await getOrigSize(1), [Math.floor(dim.width * 0.5), Math.floor(dim.height * 0.3)]);
343-
});
344-
test('palette.png: ommitted dimension assumes preserveAspectRatio=1', async () => {
345-
// width provided in percent
346-
const header = 'size=525;width=50%';
347-
await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_PNG_BASE64}\x07`);
348-
const dim = await getDimensions();
349-
const width = Math.floor(dim.width * 0.5);
350-
deepStrictEqual(await getOrigSize(1), [width, Math.floor(width * 80 / 640)]);
351-
// height provided in pixel
352-
const header2 = 'size=525;height=200px';
353-
await ctx.proxy.write(`\x1b]1337;File=inline=1;${header2}:${PALETTE_PNG_BASE64}\x07`);
354-
deepStrictEqual(await getOrigSize(2), [Math.floor(200 * 640 / 80), 200]);
355-
});
356-
});
357-
358-
test.describe('QOI support', () => {
316+
test.describe('IIP - QOI support', () => {
359317
test('palette should yield same bytes from PNG and QOI', async () => {
360318
await ctx.proxy.write(`\x1b]1337;File=inline=1;size=525:${PALETTE_PNG_BASE64}\x07`);
361319
deepStrictEqual(await getOrigSize(1), [640, 80]);
@@ -365,44 +323,56 @@ test.describe('ImageAddon', () => {
365323
const qoiScrape = await getImageAtBufferCell(0, 11);
366324
deepStrictEqual(qoiScrape, pngScrape);
367325
});
368-
test.describe.only('IIP resizing - QOI format', () => {
369-
/**
370-
* Same as the tests above, but with QOI format.
371-
* This is needed, as QOI uses a slightly different parse path.
372-
*/
373-
test('palette.qoi: N --> width=20 height=5 preserveAspectRatio=0', async () => {
326+
});
327+
328+
test.describe('IIP - resizing', () => {
329+
/**
330+
* The correct resize behavior is wonky and needs to be tested against iTerm2,
331+
* especially for missing params to derive correct default behavior.
332+
* We document the current behavior here w'o claiming to be fully in line with iTerm2.
333+
* ref: https://iterm2.com/documentation-images.html
334+
* imgcat: https://iterm2.com/utilities/imgcat
335+
*
336+
* NOTE: QOI has a slightly different parse path, thus we test resizing explicitly
337+
*/
338+
const images = [
339+
['palette.png', 525, PALETTE_PNG_BASE64],
340+
['palette.qoi', qoiData.length, PALETTE_QOI_BASE64]
341+
];
342+
for (const [name, size, payload] of images) {
343+
test(name + ': N --> width=20 height=5 preserveAspectRatio=0', async () => {
374344
// cell based resize
375-
const header = `size=${qoiData.length};width=20;height=5;preserveAspectRatio=0`;
376-
await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_QOI_BASE64}\x07`);
345+
const header = 'width=20;height=5;preserveAspectRatio=0';
346+
await ctx.proxy.write(`\x1b]1337;File=inline=1;size=${size};${header}:${payload}\x07`);
377347
const dim = await getDimensions();
378348
deepStrictEqual(await getOrigSize(1), [dim.cellWidth * 20, dim.cellHeight * 5]);
379349
});
380-
test('palette.qoi: Npx --> width=320px height=160px preserveAspectRatio=0', async () => {
350+
test(name + ': Npx --> width=320px height=160px preserveAspectRatio=0', async () => {
381351
// pixel based resize
382-
const header = `size=${qoiData.length};width=320px;height=160px;preserveAspectRatio=0`;
383-
await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_QOI_BASE64}\x07`);
352+
const header = 'width=320px;height=160px;preserveAspectRatio=0';
353+
await ctx.proxy.write(`\x1b]1337;File=inline=1;size=${size};${header}:${payload}\x07`);
384354
deepStrictEqual(await getOrigSize(1), [320, 160]);
385355
});
386-
test('palette.qoi: N% --> width=50% height=30% preserveAspectRatio=0', async () => {
356+
test(name + ': N% --> width=50% height=30% preserveAspectRatio=0', async () => {
387357
// % of viewport resize
388-
const header = `size=${qoiData.length};width=50%;height=30%;preserveAspectRatio=0`;
389-
await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_QOI_BASE64}\x07`);
358+
const header = 'width=50%;height=30%;preserveAspectRatio=0';
359+
await ctx.proxy.write(`\x1b]1337;File=inline=1;size=${size};${header}:${payload}\x07`);
390360
const dim = await getDimensions();
391361
deepStrictEqual(await getOrigSize(1), [Math.floor(dim.width * 0.5), Math.floor(dim.height * 0.3)]);
392362
});
393-
test('palette.qoi: ommitted dimension assumes preserveAspectRatio=1', async () => {
363+
test(name + ': ommitted dimension assumes preserveAspectRatio=1', async () => {
394364
// width provided in percent
395-
const header = `size=${qoiData.length};width=50%`;
396-
await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_QOI_BASE64}\x07`);
365+
const header = 'width=50%';
366+
await ctx.proxy.write(`\x1b]1337;File=inline=1;size=${size};${header}:${payload}\x07`);
397367
const dim = await getDimensions();
398368
const width = Math.floor(dim.width * 0.5);
399369
deepStrictEqual(await getOrigSize(1), [width, Math.floor(width * 80 / 640)]);
400370
// height provided in pixel
401-
const header2 = `size=${qoiData.length};height=200px`;
402-
await ctx.proxy.write(`\x1b]1337;File=inline=1;${header2}:${PALETTE_QOI_BASE64}\x07`);
371+
const header2 = 'height=200px';
372+
await ctx.proxy.write(`\x1b]1337;File=inline=1;size=${size};${header2}:${payload}\x07`);
403373
deepStrictEqual(await getOrigSize(2), [Math.floor(200 * 640 / 80), 200]);
404374
});
405-
});
375+
}
406376
});
407377
});
408378

0 commit comments

Comments
 (0)