From b2eff5ac6712ee41932184054e5f3648c6c029b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Wed, 29 Apr 2026 15:09:40 +0200 Subject: [PATCH] merge resize tests for PNG & QOI into one block --- addons/addon-image/test/ImageAddon.test.ts | 96 ++++++++-------------- 1 file changed, 33 insertions(+), 63 deletions(-) diff --git a/addons/addon-image/test/ImageAddon.test.ts b/addons/addon-image/test/ImageAddon.test.ts index 379e4615f..ac2bed61c 100644 --- a/addons/addon-image/test/ImageAddon.test.ts +++ b/addons/addon-image/test/ImageAddon.test.ts @@ -313,49 +313,7 @@ test.describe('ImageAddon', () => { }); }); - test.describe('IIP - resizing', () => { - /** - * The correct resize behavior is wonky and needs to be tested against iTerm2, - * especially for missing params to derive correct default behavior. - * We document the current behavior here w'o claiming to be fully in line with iTerm2. - * ref: https://iterm2.com/documentation-images.html - * imgcat: https://iterm2.com/utilities/imgcat - */ - test('palette.png: N --> width=20 height=5 preserveAspectRatio=0', async () => { - // cell based resize - const header = 'size=525;width=20;height=5;preserveAspectRatio=0'; - await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_PNG_BASE64}\x07`); - const dim = await getDimensions(); - deepStrictEqual(await getOrigSize(1), [dim.cellWidth * 20, dim.cellHeight * 5]); - }); - test('palette.png: Npx --> width=320px height=160px preserveAspectRatio=0', async () => { - // pixel based resize - const header = 'size=525;width=320px;height=160px;preserveAspectRatio=0'; - await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_PNG_BASE64}\x07`); - deepStrictEqual(await getOrigSize(1), [320, 160]); - }); - test('palette.png: N% --> width=50% height=30% preserveAspectRatio=0', async () => { - // % of viewport resize - const header = 'size=525;width=50%;height=30%;preserveAspectRatio=0'; - await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_PNG_BASE64}\x07`); - const dim = await getDimensions(); - deepStrictEqual(await getOrigSize(1), [Math.floor(dim.width * 0.5), Math.floor(dim.height * 0.3)]); - }); - test('palette.png: ommitted dimension assumes preserveAspectRatio=1', async () => { - // width provided in percent - const header = 'size=525;width=50%'; - await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_PNG_BASE64}\x07`); - const dim = await getDimensions(); - const width = Math.floor(dim.width * 0.5); - deepStrictEqual(await getOrigSize(1), [width, Math.floor(width * 80 / 640)]); - // height provided in pixel - const header2 = 'size=525;height=200px'; - await ctx.proxy.write(`\x1b]1337;File=inline=1;${header2}:${PALETTE_PNG_BASE64}\x07`); - deepStrictEqual(await getOrigSize(2), [Math.floor(200 * 640 / 80), 200]); - }); - }); - - test.describe('QOI support', () => { + test.describe('IIP - QOI support', () => { test('palette should yield same bytes from PNG and QOI', async () => { await ctx.proxy.write(`\x1b]1337;File=inline=1;size=525:${PALETTE_PNG_BASE64}\x07`); deepStrictEqual(await getOrigSize(1), [640, 80]); @@ -365,44 +323,56 @@ test.describe('ImageAddon', () => { const qoiScrape = await getImageAtBufferCell(0, 11); deepStrictEqual(qoiScrape, pngScrape); }); - test.describe.only('IIP resizing - QOI format', () => { - /** - * Same as the tests above, but with QOI format. - * This is needed, as QOI uses a slightly different parse path. - */ - test('palette.qoi: N --> width=20 height=5 preserveAspectRatio=0', async () => { + }); + + test.describe('IIP - resizing', () => { + /** + * The correct resize behavior is wonky and needs to be tested against iTerm2, + * especially for missing params to derive correct default behavior. + * We document the current behavior here w'o claiming to be fully in line with iTerm2. + * ref: https://iterm2.com/documentation-images.html + * imgcat: https://iterm2.com/utilities/imgcat + * + * NOTE: QOI has a slightly different parse path, thus we test resizing explicitly + */ + const images = [ + ['palette.png', 525, PALETTE_PNG_BASE64], + ['palette.qoi', qoiData.length, PALETTE_QOI_BASE64] + ]; + for (const [name, size, payload] of images) { + test(name + ': N --> width=20 height=5 preserveAspectRatio=0', async () => { // cell based resize - const header = `size=${qoiData.length};width=20;height=5;preserveAspectRatio=0`; - await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_QOI_BASE64}\x07`); + const header = 'width=20;height=5;preserveAspectRatio=0'; + await ctx.proxy.write(`\x1b]1337;File=inline=1;size=${size};${header}:${payload}\x07`); const dim = await getDimensions(); deepStrictEqual(await getOrigSize(1), [dim.cellWidth * 20, dim.cellHeight * 5]); }); - test('palette.qoi: Npx --> width=320px height=160px preserveAspectRatio=0', async () => { + test(name + ': Npx --> width=320px height=160px preserveAspectRatio=0', async () => { // pixel based resize - const header = `size=${qoiData.length};width=320px;height=160px;preserveAspectRatio=0`; - await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_QOI_BASE64}\x07`); + const header = 'width=320px;height=160px;preserveAspectRatio=0'; + await ctx.proxy.write(`\x1b]1337;File=inline=1;size=${size};${header}:${payload}\x07`); deepStrictEqual(await getOrigSize(1), [320, 160]); }); - test('palette.qoi: N% --> width=50% height=30% preserveAspectRatio=0', async () => { + test(name + ': N% --> width=50% height=30% preserveAspectRatio=0', async () => { // % of viewport resize - const header = `size=${qoiData.length};width=50%;height=30%;preserveAspectRatio=0`; - await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_QOI_BASE64}\x07`); + const header = 'width=50%;height=30%;preserveAspectRatio=0'; + await ctx.proxy.write(`\x1b]1337;File=inline=1;size=${size};${header}:${payload}\x07`); const dim = await getDimensions(); deepStrictEqual(await getOrigSize(1), [Math.floor(dim.width * 0.5), Math.floor(dim.height * 0.3)]); }); - test('palette.qoi: ommitted dimension assumes preserveAspectRatio=1', async () => { + test(name + ': ommitted dimension assumes preserveAspectRatio=1', async () => { // width provided in percent - const header = `size=${qoiData.length};width=50%`; - await ctx.proxy.write(`\x1b]1337;File=inline=1;${header}:${PALETTE_QOI_BASE64}\x07`); + const header = 'width=50%'; + await ctx.proxy.write(`\x1b]1337;File=inline=1;size=${size};${header}:${payload}\x07`); const dim = await getDimensions(); const width = Math.floor(dim.width * 0.5); deepStrictEqual(await getOrigSize(1), [width, Math.floor(width * 80 / 640)]); // height provided in pixel - const header2 = `size=${qoiData.length};height=200px`; - await ctx.proxy.write(`\x1b]1337;File=inline=1;${header2}:${PALETTE_QOI_BASE64}\x07`); + const header2 = 'height=200px'; + await ctx.proxy.write(`\x1b]1337;File=inline=1;size=${size};${header2}:${payload}\x07`); deepStrictEqual(await getOrigSize(2), [Math.floor(200 * 640 / 80), 200]); }); - }); + } }); });