import { describe, expect, test } from 'bun:test'; import { wrapText } from './wrap'; describe('wrapText', () => { test('preserves short lines unchanged', () => { expect(wrapText('hello world', 80)).toEqual(['hello world']); }); test('preserves existing newlines as line breaks', () => { expect(wrapText('a\nb\nc', 80)).toEqual(['a', 'b', 'c']); }); test('empty input lines render as single space (visible blank row)', () => { expect(wrapText('a\n\nb', 80)).toEqual(['a', ' ', 'b']); }); test('word-wraps long lines on whitespace', () => { const result = wrapText('the quick brown fox jumps over the lazy dog', 15); expect(result.every((line) => line.length <= 15)).toBe(true); expect(result.join(' ').replace(/\s+/g, ' ')).toBe( 'the quick brown fox jumps over the lazy dog', ); }); test('hard-breaks words longer than the width', () => { const result = wrapText('xxxxxxxxxxxxxxxxxxxx', 5); expect(result.every((line) => line.length <= 5)).toBe(true); expect(result.join('')).toBe('xxxxxxxxxxxxxxxxxxxx'); }); test('mix of short, long, and blank lines', () => { const text = ['short', '', 'a much longer sentence that needs to wrap'].join('\n'); const result = wrapText(text, 20); // First line: short stays as-is expect(result[0]).toBe('short'); // Second line: blank → space expect(result[1]).toBe(' '); // Subsequent lines: each <= 20 for (const line of result.slice(2)) { expect(line.length).toBeLessThanOrEqual(20); } }); });