|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { test } from 'node:test'; |
| 3 | +import { countMotivatingClones, namedConstantRange } from './prototype-report.ts'; |
| 4 | + |
| 5 | +const source = `// const IPHONE_DUO_CLOSED = "😀 comment, not the fixture"; |
| 6 | +const other = { nativeSize: [1, 2] }; |
| 7 | +const IPHONE_DUO_CLOSED = JSON.stringify({ |
| 8 | + result: { |
| 9 | + displays: [ |
| 10 | + { active: true, nativeSize: [1398, 2034] }, |
| 11 | + { active: false, nativeSize: [2007, 2853] }, |
| 12 | + ], |
| 13 | + }, |
| 14 | +}); |
| 15 | +const singlePanel = { active: true }; |
| 16 | +`; |
| 17 | + |
| 18 | +test('Duo range follows its named constant after line shifts and ignores comment decoys', () => { |
| 19 | + assert.deepEqual(namedConstantRange(source, 'IPHONE_DUO_CLOSED'), { start: 3, end: 10 }); |
| 20 | + assert.deepEqual(namedConstantRange('\n'.repeat(40) + source, 'IPHONE_DUO_CLOSED'), { |
| 21 | + start: 43, |
| 22 | + end: 50, |
| 23 | + }); |
| 24 | + assert.throws(() => namedConstantRange(source, 'RENAMED_FIXTURE'), /RENAMED_FIXTURE/); |
| 25 | +}); |
| 26 | + |
| 27 | +for (const separator of ['/', '\\']) { |
| 28 | + test(`motivating clone counts accept ${JSON.stringify(separator)} paths and shifted fixture lines`, () => { |
| 29 | + const target = ['checkout', 'simctl-facade.test.ts'].join(separator); |
| 30 | + const other = ['checkout', 'display-inventory.test.ts'].join(separator); |
| 31 | + const fold = ['checkout', 'apple', 'fold-helper', 'Fold.m'].join(separator); |
| 32 | + const counts = countMotivatingClones( |
| 33 | + [ |
| 34 | + { |
| 35 | + firstFile: { name: fold, start: 2, end: 8 }, |
| 36 | + secondFile: { name: fold, start: 12, end: 18 }, |
| 37 | + }, |
| 38 | + { |
| 39 | + firstFile: { name: target, start: 45, end: 47 }, |
| 40 | + secondFile: { name: other, start: 70, end: 72 }, |
| 41 | + }, |
| 42 | + { |
| 43 | + firstFile: { name: other, start: 73, end: 75 }, |
| 44 | + secondFile: { name: target, start: 48, end: 50 }, |
| 45 | + }, |
| 46 | + { |
| 47 | + firstFile: { name: target, start: 51, end: 60 }, |
| 48 | + secondFile: { name: other, start: 80, end: 89 }, |
| 49 | + }, |
| 50 | + { |
| 51 | + firstFile: { name: target, start: 41, end: 42 }, |
| 52 | + secondFile: { name: other, start: 5, end: 6 }, |
| 53 | + }, |
| 54 | + { |
| 55 | + firstFile: { name: target, start: 45, end: 47 }, |
| 56 | + secondFile: { name: target, start: 48, end: 50 }, |
| 57 | + }, |
| 58 | + ], |
| 59 | + namedConstantRange('\n'.repeat(40) + source, 'IPHONE_DUO_CLOSED'), |
| 60 | + ); |
| 61 | + assert.deepEqual(counts, { fold: 1, duoPanels: 2 }); |
| 62 | + }); |
| 63 | +} |
0 commit comments