spacehub

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

claude-code / mods / diff / tests / git / parse / parse-numstat.test.ts
67 lines · 1.8 KBRaw
1import { describe, expect, test, tier } from 'claude-code/testing'
2
3import Parse from '../../../hooks/git/parse'
4import Limits from '../../../hooks/limits'
5
6tier('builtin')
7
8describe('parse-numstat', () => {
9 test('NUL records: totals, binaries at 0/0, tabs in a path kept', () => {
10 const parsed = Parse.parseNumstat(
11 '3\t1\tsrc/a.ts\0-\t-\timg.png\x002\t0\ta\tb.ts\0',
12 Limits.MAX_FILES,
13 )
14
15 expect(parsed.stats).toEqual({
16 filesCount: 3,
17 linesAdded: 5,
18 linesRemoved: 1,
19 })
20
21 expect(parsed.files.map(file => [file.path, file.isBinary])).toEqual([
22 ['src/a.ts', false],
23 ['img.png', true],
24 ['a\tb.ts', false],
25 ])
26
27 expect(
28 parsed.files.every(file => !file.isUntracked && !file.isPreSession),
29 ).toBe(true)
30 })
31
32 test('the cap keeps the first rows but counts every row', () => {
33 const parsed = Parse.parseNumstat('1\t0\ta\x001\t0\tb\x001\t0\tc\0', 2)
34
35 expect(parsed.files.map(file => file.path)).toEqual(['a', 'b'])
36 expect(parsed.stats.filesCount).toBe(3)
37 })
38
39 test('a line with fewer than three fields is no row', () => {
40 expect(
41 Parse.parseNumstat('\0warning: x\0', Limits.MAX_FILES).stats.filesCount,
42 ).toBe(0)
43 })
44
45 test('a non-ASCII path arrives as its own characters', () => {
46 expect(
47 Parse.parseNumstat('1\t1\tdocs/caf\u00e9.md\0', Limits.MAX_FILES).files[0]
48 ?.path,
49 ).toBe('docs/caf\u00e9.md')
50 })
51
52 test('a rename record keeps the new path and remembers the old', () => {
53 const parsed = Parse.parseNumstat(
54 '2\t1\t\0src/old.ts\0src/new.ts\x003\t0\tkept.ts\0',
55 Limits.MAX_FILES,
56 )
57
58 expect(
59 parsed.files.map(file => [file.path, file.renamedFrom, file.added]),
60 ).toEqual([
61 ['src/new.ts', 'src/old.ts', 2],
62 ['kept.ts', null, 3],
63 ])
64
65 expect(parsed.stats.filesCount).toBe(2)
66 })
67})