From 53870d58bb575e72591c145761cf6c9e5fd42d00 Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Fri, 5 Jun 2026 18:23:48 +0530 Subject: [PATCH] test(renderer): clarify ascii-table alignment tests (left vs right) --- tests/unit/lib/ascii-table.test.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/unit/lib/ascii-table.test.ts b/tests/unit/lib/ascii-table.test.ts index 2d6ecb0..9bf5a44 100644 --- a/tests/unit/lib/ascii-table.test.ts +++ b/tests/unit/lib/ascii-table.test.ts @@ -15,17 +15,31 @@ describe('toAsciiTable', () => { expect(toAsciiTable([])).toBe(''); }); - it('aligns numeric columns to the right', () => { + it('left-aligns non-numeric columns', () => { // With header 'Price' (starts with P, not digit), all columns are left-aligned. - // Price column width = 5 (from 'Price'), so '100' -> '100 ', '7' -> '7 '. + // Col 0 width = max(4,1,2) = 4 (from 'Item'); col 1 width = max(5,3,1) = 5 (from 'Price'). const out = toAsciiTable([ ['Item', 'Price'], ['X', '100'], ['YY', '7'], ]); - expect(out).toContain('| 100 |'); - expect(out).toContain('| 7 |'); + expect(out).toContain('| X | 100 |'); + expect(out).toContain('| YY | 7 |'); }); + + it('right-aligns all columns when any header starts with a digit', () => { + // Header '7' starts with a digit -> right-align all columns. + // Col 0 width = max(4,1,2) = 4 (from 'Item'); col 1 width = max(1,3,2) = 3 (from '100'). + const out = toAsciiTable([ + ['Item', '7'], + ['X', '100'], + ['YY', '25'], + ]); + // Right-aligned: "X" padStart(4) -> " X", "100" padStart(3) -> "100" + expect(out).toContain('| X | 100 |'); + // Right-aligned: "YY" padStart(4) -> " YY", "25" padStart(3) -> " 25" + expect(out).toContain('| YY | 25 |'); + }); }); describe('applyAsciiTransform', () => {