import { describe, expect, it } from 'vitest' import { tailDiffHunk, threadDiffLines } from './pr-comment-diff-hunk' const HUNK = [ '@@ -20,4 +20,6 @@ export function Banner(props) {', ' return (', '- ', '+ ', '+ ', ' {props.title}' ].join('\n') describe('pr comment diff hunk', () => { it('numbers the anchored lines back from the end line, skipping removed lines', () => { const tail = tailDiffHunk(HUNK) ?? '' const strip = (lines: ReturnType) => lines.map(({ number, sign, text }) => ({ number, sign, text })) expect(strip(threadDiffLines(tail, 23))).toEqual([ { number: 23, sign: ' ', text: ' {props.title}' } ]) // A hunk ending on line 21 with a removal inside 20..21: it shows unnumbered and line 20 still shows. const toLine21 = tail.split('\n').slice(0, 3).join('\n') expect(strip(threadDiffLines(toLine21, 21, 20))).toEqual([ { number: 20, sign: ' ', text: ' return (' }, { number: null, sign: '-', text: ' ' }, { number: 21, sign: '+', text: ' ' } ]) }) })