surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | import { describe, expect, test, tier } from 'claude-code/testing' |
| 2 | |
| 3 | import Parse from '../../../hooks/git/parse' |
| 4 | import Limits from '../../../hooks/limits' |
| 5 | import Fixtures from '../../fixtures' |
| 6 | |
| 7 | tier('builtin') |
| 8 | |
| 9 | describe('parse-file-diff', () => { |
| 10 | test('hunk starts and marked lines; header and notes skipped', () => { |
| 11 | const parsed = Parse.parseFileDiff( |
| 12 | `${Fixtures.FILE_DIFF_HEADER}@@ -1,3 +1,3 @@\n one\n-two\n+two ` + |
| 13 | `changed\n three\n\\ No newline at end of file\n@@ -10 +10,2 @@ fn\n ` + |
| 14 | `ctx\n+added\n`, |
| 15 | ) |
| 16 | |
| 17 | expect(parsed.isLarge).toBe(false) |
| 18 | expect(parsed.isTruncated).toBe(false) |
| 19 | |
| 20 | expect(parsed.hunks).toEqual([ |
| 21 | { |
| 22 | oldStart: 1, |
| 23 | newStart: 1, |
| 24 | lines: [' one', '-two', '+two changed', ' three'], |
| 25 | }, |
| 26 | { oldStart: 10, newStart: 10, lines: [' ctx', '+added'] }, |
| 27 | ]) |
| 28 | }) |
| 29 | |
| 30 | test('a removed line that starts with dashes is body, not a header', () => { |
| 31 | expect( |
| 32 | Parse.parseFileDiff( |
| 33 | `${Fixtures.FILE_DIFF_HEADER}@@ -1 +1 @@\n---- old rule\n+--- new ` + |
| 34 | `rule\n`, |
| 35 | ).hunks[0]?.lines, |
| 36 | ).toEqual(['---- old rule', '+--- new rule']) |
| 37 | }) |
| 38 | |
| 39 | test('the body is cut at the line cap and marked truncated', () => { |
| 40 | const body = Array.from( |
| 41 | { length: Limits.MAX_LINES_PER_FILE + Fixtures.PAST_THE_CAP }, |
| 42 | (_, at) => `+${at}`, |
| 43 | ).join('\n') |
| 44 | |
| 45 | const parsed = Parse.parseFileDiff( |
| 46 | `${Fixtures.FILE_DIFF_HEADER}@@ -0,0 +1,405 @@\n${body}\n`, |
| 47 | ) |
| 48 | |
| 49 | expect(parsed.hunks[0]?.lines).toHaveLength(Limits.MAX_LINES_PER_FILE) |
| 50 | expect(parsed.isTruncated).toBe(true) |
| 51 | }) |
| 52 | |
| 53 | test('a diff past the byte cap is large and has no hunks', () => { |
| 54 | expect( |
| 55 | Parse.parseFileDiff( |
| 56 | `${Fixtures.FILE_DIFF_HEADER}@@ -1 +1 ` + |
| 57 | `@@\n+${'x'.repeat(Limits.MAX_DIFF_BYTES)}\n`, |
| 58 | ), |
| 59 | ).toEqual({ hunks: [], isTruncated: false, isLarge: true }) |
| 60 | }) |
| 61 | }) |