MCPcopy Create free account
hub / github.com/anus-dev/ANUS / createMockBuffer

Function createMockBuffer

packages/cli/src/ui/hooks/vim.test.ts:52–136  ·  view source on GitHub ↗
(
    text = 'hello world',
    cursor: [number, number] = [0, 5],
  )

Source from the content-addressed store, hash-verified

50 let mockHandleFinalSubmit: vi.Mock;
51
52 const createMockBuffer = (
53 text = 'hello world',
54 cursor: [number, number] = [0, 5],
55 ) => {
56 const cursorState = { pos: cursor };
57 const lines = text.split('\n');
58
59 return {
60 lines,
61 get cursor() {
62 return cursorState.pos;
63 },
64 set cursor(newPos: [number, number]) {
65 cursorState.pos = newPos;
66 },
67 text,
68 move: vi.fn().mockImplementation((direction: string) => {
69 let [row, col] = cursorState.pos;
70 const _line = lines[row] || '';
71 if (direction === 'left') {
72 col = Math.max(0, col - 1);
73 } else if (direction === 'right') {
74 col = Math.min(line.length, col + 1);
75 } else if (direction === 'home') {
76 col = 0;
77 } else if (direction === 'end') {
78 col = line.length;
79 }
80 cursorState.pos = [row, col];
81 }),
82 del: vi.fn(),
83 moveToOffset: vi.fn(),
84 insert: vi.fn(),
85 newline: vi.fn(),
86 replaceRangeByOffset: vi.fn(),
87 handleInput: vi.fn(),
88 setText: vi.fn(),
89 // Vim-specific methods
90 vimDeleteWordForward: vi.fn(),
91 vimDeleteWordBackward: vi.fn(),
92 vimDeleteWordEnd: vi.fn(),
93 vimChangeWordForward: vi.fn(),
94 vimChangeWordBackward: vi.fn(),
95 vimChangeWordEnd: vi.fn(),
96 vimDeleteLine: vi.fn(),
97 vimChangeLine: vi.fn(),
98 vimDeleteToEndOfLine: vi.fn(),
99 vimChangeToEndOfLine: vi.fn(),
100 vimChangeMovement: vi.fn(),
101 vimMoveLeft: vi.fn(),
102 vimMoveRight: vi.fn(),
103 vimMoveUp: vi.fn(),
104 vimMoveDown: vi.fn(),
105 vimMoveWordForward: vi.fn(),
106 vimMoveWordBackward: vi.fn(),
107 vimMoveWordEnd: vi.fn(),
108 vimDeleteChar: vi.fn(),
109 vimInsertAtCursor: vi.fn(),

Callers 1

vim.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected