/*** 皮肤包冒烟:只测纯逻辑(今日覆盖行级差异对齐),DOM 渲染靠演示页人工过 ***/ import { alignMiddle, diffLines, normalizeLine, toRows, DP_LIMIT } from '../dist/diffKit.js'; let failed = 0; /*** 断言:打印一条结果,失败计数 +1 ***/ const ok = (label, cond) => { if (cond) { console.log(`ok - ${label}`); return; } console.error(`FAIL - ${label}`); failed += 1; }; // 1) 完全相同:全是 same,没有增删 const same = diffLines('a\nb\nc', 'a\nb\nc', false); ok('相同文本全是 same', same.length === 3 && same.every((o) => o.type === 'same')); // 2) 纯新增一行 const added = diffLines('a\nc', 'a\nb\nc', false); ok('中间插入一行 → 恰好 1 条 add', added.filter((o) => o.type === 'add').length === 1 && added.filter((o) => o.type === 'del').length === 0); // 3) 纯删除一行 const removed = diffLines('a\nb\nc', 'a\nc', false); ok('中间删除一行 → 恰好 1 条 del', removed.filter((o) => o.type === 'del').length === 1 && removed.filter((o) => o.type === 'add').length === 0); // 4) 尾部换行不产生假差异 ok('尾部换行不算差异', diffLines('a\nb\n', 'a\nb', false).every((o) => o.type === 'same')); // 5) 忽略行内空白:只差缩进时无增删,且显示保留原文 const ws = diffLines('if (a) {\n return 1;\n}', 'if (a) {\n return 1;\n}', true); ok('忽略空白后缩进差不计入差异', ws.every((o) => o.type === 'same') && ws[1].text.includes(' ')); // 6) 不忽略空白时同一对文本必须报差异(对照组:证明开关真的起作用) ok('不忽略空白时同一对文本报增删', diffLines('if (a) {\n return 1;\n}', 'if (a) {\n return 1;\n}', false).some((o) => o.type !== 'same')); // 7) 行内多空格归一 ok('行内连续空白压成一个空格', normalizeLine(' a b\t c ') === 'a b c'); // 8) 超限退化:仍保证「旧行全 del + 新行全 add」,不丢内容 const bigA = Array.from({ length: 700 }, (_, i) => `a${i}`); const bigB = Array.from({ length: 700 }, (_, i) => `b${i}`); const big = alignMiddle(toRows(bigA.join('\n'), false), toRows(bigB.join('\n'), false)); ok(`超限(>${DP_LIMIT})退化为整段替换`, big.filter((o) => o.type === 'del').length === 700 && big.filter((o) => o.type === 'add').length === 700); if (failed) { console.error(`皮肤冒烟失败 ${failed} 条`); process.exit(1); } console.log('SKIN SMOKE OK');