mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
Refactor vim.test.ts: Use Parameterized Tests (#11969)
This commit is contained in:
@@ -14,6 +14,7 @@ import type { Key } from './useKeypress.js';
|
|||||||
import type {
|
import type {
|
||||||
TextBuffer,
|
TextBuffer,
|
||||||
TextBufferState,
|
TextBufferState,
|
||||||
|
TextBufferAction,
|
||||||
} from '../components/shared/text-buffer.js';
|
} from '../components/shared/text-buffer.js';
|
||||||
import { textBufferReducer } from '../components/shared/text-buffer.js';
|
import { textBufferReducer } from '../components/shared/text-buffer.js';
|
||||||
|
|
||||||
@@ -1355,391 +1356,249 @@ describe('useVim hook', () => {
|
|||||||
// Line operations (dd, cc) are tested in text-buffer.test.ts
|
// Line operations (dd, cc) are tested in text-buffer.test.ts
|
||||||
|
|
||||||
describe('Reducer-based integration tests', () => {
|
describe('Reducer-based integration tests', () => {
|
||||||
describe('de (delete word end)', () => {
|
type VimActionType =
|
||||||
it('should delete from cursor to end of current word', () => {
|
| 'vim_delete_word_end'
|
||||||
const initialState = createMockTextBufferState({
|
| 'vim_delete_word_backward'
|
||||||
|
| 'vim_change_word_forward'
|
||||||
|
| 'vim_change_word_end'
|
||||||
|
| 'vim_change_word_backward'
|
||||||
|
| 'vim_change_line'
|
||||||
|
| 'vim_delete_line'
|
||||||
|
| 'vim_delete_to_end_of_line'
|
||||||
|
| 'vim_change_to_end_of_line';
|
||||||
|
|
||||||
|
type VimReducerTestCase = {
|
||||||
|
command: string;
|
||||||
|
desc: string;
|
||||||
|
lines: string[];
|
||||||
|
cursorRow: number;
|
||||||
|
cursorCol: number;
|
||||||
|
actionType: VimActionType;
|
||||||
|
count?: number;
|
||||||
|
expectedLines: string[];
|
||||||
|
expectedCursorRow: number;
|
||||||
|
expectedCursorCol: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const testCases: VimReducerTestCase[] = [
|
||||||
|
{
|
||||||
|
command: 'de',
|
||||||
|
desc: 'delete from cursor to end of current word',
|
||||||
lines: ['hello world test'],
|
lines: ['hello world test'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 1, // cursor on 'e' in "hello"
|
cursorCol: 1,
|
||||||
preferredCol: null,
|
actionType: 'vim_delete_word_end' as const,
|
||||||
undoStack: [],
|
count: 1,
|
||||||
redoStack: [],
|
expectedLines: ['h world test'],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 1,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'de',
|
||||||
type: 'vim_delete_word_end',
|
desc: 'delete multiple word ends with count',
|
||||||
payload: { count: 1 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "ello" (from cursor to end of word), leaving "h world test"
|
|
||||||
expect(result.lines).toEqual(['h world test']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete multiple word ends with count', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world test more'],
|
lines: ['hello world test more'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 1, // cursor on 'e' in "hello"
|
cursorCol: 1,
|
||||||
preferredCol: null,
|
actionType: 'vim_delete_word_end' as const,
|
||||||
undoStack: [],
|
count: 2,
|
||||||
redoStack: [],
|
expectedLines: ['h test more'],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 1,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'db',
|
||||||
type: 'vim_delete_word_end',
|
desc: 'delete from cursor to start of previous word',
|
||||||
payload: { count: 2 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "ello world" (to end of second word), leaving "h test more"
|
|
||||||
expect(result.lines).toEqual(['h test more']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('db (delete word backward)', () => {
|
|
||||||
it('should delete from cursor to start of previous word', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world test'],
|
lines: ['hello world test'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 11, // cursor on 't' in "test"
|
cursorCol: 11,
|
||||||
preferredCol: null,
|
actionType: 'vim_delete_word_backward' as const,
|
||||||
undoStack: [],
|
count: 1,
|
||||||
redoStack: [],
|
expectedLines: ['hello test'],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 6,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'db',
|
||||||
type: 'vim_delete_word_backward',
|
desc: 'delete multiple words backward with count',
|
||||||
payload: { count: 1 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "world" (previous word only), leaving "hello test"
|
|
||||||
expect(result.lines).toEqual(['hello test']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(6);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete multiple words backward with count', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world test more'],
|
lines: ['hello world test more'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 17, // cursor on 'm' in "more"
|
cursorCol: 17,
|
||||||
preferredCol: null,
|
actionType: 'vim_delete_word_backward' as const,
|
||||||
undoStack: [],
|
count: 2,
|
||||||
redoStack: [],
|
expectedLines: ['hello more'],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 6,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'cw',
|
||||||
type: 'vim_delete_word_backward',
|
desc: 'delete from cursor to start of next word',
|
||||||
payload: { count: 2 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "world test " (two words backward), leaving "hello more"
|
|
||||||
expect(result.lines).toEqual(['hello more']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(6);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('cw (change word forward)', () => {
|
|
||||||
it('should delete from cursor to start of next word', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world test'],
|
lines: ['hello world test'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 0, // cursor on 'h' in "hello"
|
cursorCol: 0,
|
||||||
preferredCol: null,
|
actionType: 'vim_change_word_forward' as const,
|
||||||
undoStack: [],
|
count: 1,
|
||||||
redoStack: [],
|
expectedLines: ['world test'],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 0,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'cw',
|
||||||
type: 'vim_change_word_forward',
|
desc: 'change multiple words with count',
|
||||||
payload: { count: 1 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "hello " (word + space), leaving "world test"
|
|
||||||
expect(result.lines).toEqual(['world test']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should change multiple words with count', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world test more'],
|
lines: ['hello world test more'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 0,
|
cursorCol: 0,
|
||||||
preferredCol: null,
|
actionType: 'vim_change_word_forward' as const,
|
||||||
undoStack: [],
|
count: 2,
|
||||||
redoStack: [],
|
expectedLines: ['test more'],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 0,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'ce',
|
||||||
type: 'vim_change_word_forward',
|
desc: 'change from cursor to end of current word',
|
||||||
payload: { count: 2 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "hello world " (two words), leaving "test more"
|
|
||||||
expect(result.lines).toEqual(['test more']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('ce (change word end)', () => {
|
|
||||||
it('should change from cursor to end of current word', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world test'],
|
lines: ['hello world test'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 1, // cursor on 'e' in "hello"
|
cursorCol: 1,
|
||||||
preferredCol: null,
|
actionType: 'vim_change_word_end' as const,
|
||||||
undoStack: [],
|
count: 1,
|
||||||
redoStack: [],
|
expectedLines: ['h world test'],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 1,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'ce',
|
||||||
type: 'vim_change_word_end',
|
desc: 'change multiple word ends with count',
|
||||||
payload: { count: 1 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "ello" (from cursor to end of word), leaving "h world test"
|
|
||||||
expect(result.lines).toEqual(['h world test']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should change multiple word ends with count', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world test'],
|
lines: ['hello world test'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 1, // cursor on 'e' in "hello"
|
cursorCol: 1,
|
||||||
preferredCol: null,
|
actionType: 'vim_change_word_end' as const,
|
||||||
undoStack: [],
|
count: 2,
|
||||||
redoStack: [],
|
expectedLines: ['h test'],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 1,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'cb',
|
||||||
type: 'vim_change_word_end',
|
desc: 'change from cursor to start of previous word',
|
||||||
payload: { count: 2 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "ello world" (to end of second word), leaving "h test"
|
|
||||||
expect(result.lines).toEqual(['h test']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('cb (change word backward)', () => {
|
|
||||||
it('should change from cursor to start of previous word', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world test'],
|
lines: ['hello world test'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 11, // cursor on 't' in "test"
|
cursorCol: 11,
|
||||||
preferredCol: null,
|
actionType: 'vim_change_word_backward' as const,
|
||||||
undoStack: [],
|
count: 1,
|
||||||
redoStack: [],
|
expectedLines: ['hello test'],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 6,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'cc',
|
||||||
type: 'vim_change_word_backward',
|
desc: 'clear the line and place cursor at the start',
|
||||||
payload: { count: 1 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "world" (previous word only), leaving "hello test"
|
|
||||||
expect(result.lines).toEqual(['hello test']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(6);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('cc (change line)', () => {
|
|
||||||
it('should clear the line and place cursor at the start', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: [' hello world'],
|
lines: [' hello world'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 5, // cursor on 'o'
|
cursorCol: 5,
|
||||||
preferredCol: null,
|
actionType: 'vim_change_line' as const,
|
||||||
undoStack: [],
|
count: 1,
|
||||||
redoStack: [],
|
expectedLines: [''],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 0,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'dd',
|
||||||
type: 'vim_change_line',
|
desc: 'delete the current line',
|
||||||
payload: { count: 1 },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.lines).toEqual(['']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('dd (delete line)', () => {
|
|
||||||
it('should delete the current line', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['line1', 'line2', 'line3'],
|
lines: ['line1', 'line2', 'line3'],
|
||||||
cursorRow: 1,
|
cursorRow: 1,
|
||||||
cursorCol: 2,
|
cursorCol: 2,
|
||||||
preferredCol: null,
|
actionType: 'vim_delete_line' as const,
|
||||||
undoStack: [],
|
count: 1,
|
||||||
redoStack: [],
|
expectedLines: ['line1', 'line3'],
|
||||||
clipboard: null,
|
expectedCursorRow: 1,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 0,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'dd',
|
||||||
type: 'vim_delete_line',
|
desc: 'delete multiple lines with count',
|
||||||
payload: { count: 1 },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.lines).toEqual(['line1', 'line3']);
|
|
||||||
expect(result.cursorRow).toBe(1);
|
|
||||||
expect(result.cursorCol).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete multiple lines with count', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['line1', 'line2', 'line3', 'line4'],
|
lines: ['line1', 'line2', 'line3', 'line4'],
|
||||||
cursorRow: 1,
|
cursorRow: 1,
|
||||||
cursorCol: 2,
|
cursorCol: 2,
|
||||||
preferredCol: null,
|
actionType: 'vim_delete_line' as const,
|
||||||
undoStack: [],
|
count: 2,
|
||||||
redoStack: [],
|
expectedLines: ['line1', 'line4'],
|
||||||
clipboard: null,
|
expectedCursorRow: 1,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 0,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'dd',
|
||||||
type: 'vim_delete_line',
|
desc: 'handle deleting last line',
|
||||||
payload: { count: 2 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete lines 1 and 2
|
|
||||||
expect(result.lines).toEqual(['line1', 'line4']);
|
|
||||||
expect(result.cursorRow).toBe(1);
|
|
||||||
expect(result.cursorCol).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle deleting last line', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['only line'],
|
lines: ['only line'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 3,
|
cursorCol: 3,
|
||||||
preferredCol: null,
|
actionType: 'vim_delete_line' as const,
|
||||||
undoStack: [],
|
count: 1,
|
||||||
redoStack: [],
|
expectedLines: [''],
|
||||||
clipboard: null,
|
expectedCursorRow: 0,
|
||||||
selectionAnchor: null,
|
expectedCursorCol: 0,
|
||||||
});
|
},
|
||||||
|
{
|
||||||
const result = textBufferReducer(initialState, {
|
command: 'D',
|
||||||
type: 'vim_delete_line',
|
desc: 'delete from cursor to end of line',
|
||||||
payload: { count: 1 },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should leave an empty line when deleting the only line
|
|
||||||
expect(result.lines).toEqual(['']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('D (delete to end of line)', () => {
|
|
||||||
it('should delete from cursor to end of line', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world test'],
|
lines: ['hello world test'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 6, // cursor on 'w' in "world"
|
cursorCol: 6,
|
||||||
preferredCol: null,
|
actionType: 'vim_delete_to_end_of_line' as const,
|
||||||
undoStack: [],
|
expectedLines: ['hello '],
|
||||||
redoStack: [],
|
expectedCursorRow: 0,
|
||||||
clipboard: null,
|
expectedCursorCol: 6,
|
||||||
selectionAnchor: null,
|
},
|
||||||
});
|
{
|
||||||
|
command: 'D',
|
||||||
const result = textBufferReducer(initialState, {
|
desc: 'handle D at end of line',
|
||||||
type: 'vim_delete_to_end_of_line',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "world test", leaving "hello "
|
|
||||||
expect(result.lines).toEqual(['hello ']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(6);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle D at end of line', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world'],
|
lines: ['hello world'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 11, // cursor at end
|
cursorCol: 11,
|
||||||
preferredCol: null,
|
actionType: 'vim_delete_to_end_of_line' as const,
|
||||||
undoStack: [],
|
expectedLines: ['hello world'],
|
||||||
redoStack: [],
|
expectedCursorRow: 0,
|
||||||
clipboard: null,
|
expectedCursorCol: 11,
|
||||||
selectionAnchor: null,
|
},
|
||||||
});
|
{
|
||||||
|
command: 'C',
|
||||||
const result = textBufferReducer(initialState, {
|
desc: 'change from cursor to end of line',
|
||||||
type: 'vim_delete_to_end_of_line',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should not change anything when at end of line
|
|
||||||
expect(result.lines).toEqual(['hello world']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(11);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('C (change to end of line)', () => {
|
|
||||||
it('should change from cursor to end of line', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world test'],
|
lines: ['hello world test'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 6, // cursor on 'w' in "world"
|
cursorCol: 6,
|
||||||
preferredCol: null,
|
actionType: 'vim_change_to_end_of_line' as const,
|
||||||
undoStack: [],
|
expectedLines: ['hello '],
|
||||||
redoStack: [],
|
expectedCursorRow: 0,
|
||||||
clipboard: null,
|
expectedCursorCol: 6,
|
||||||
selectionAnchor: null,
|
},
|
||||||
});
|
{
|
||||||
|
command: 'C',
|
||||||
const result = textBufferReducer(initialState, {
|
desc: 'handle C at beginning of line',
|
||||||
type: 'vim_change_to_end_of_line',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should delete "world test", leaving "hello "
|
|
||||||
expect(result.lines).toEqual(['hello ']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
|
||||||
expect(result.cursorCol).toBe(6);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle C at beginning of line', () => {
|
|
||||||
const initialState = createMockTextBufferState({
|
|
||||||
lines: ['hello world'],
|
lines: ['hello world'],
|
||||||
cursorRow: 0,
|
cursorRow: 0,
|
||||||
cursorCol: 0,
|
cursorCol: 0,
|
||||||
|
actionType: 'vim_change_to_end_of_line' as const,
|
||||||
|
expectedLines: [''],
|
||||||
|
expectedCursorRow: 0,
|
||||||
|
expectedCursorCol: 0,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
it.each(testCases)(
|
||||||
|
'$command: should $desc',
|
||||||
|
({
|
||||||
|
lines,
|
||||||
|
cursorRow,
|
||||||
|
cursorCol,
|
||||||
|
actionType,
|
||||||
|
count,
|
||||||
|
expectedLines,
|
||||||
|
expectedCursorRow,
|
||||||
|
expectedCursorCol,
|
||||||
|
}: VimReducerTestCase) => {
|
||||||
|
const initialState = createMockTextBufferState({
|
||||||
|
lines,
|
||||||
|
cursorRow,
|
||||||
|
cursorCol,
|
||||||
preferredCol: null,
|
preferredCol: null,
|
||||||
undoStack: [],
|
undoStack: [],
|
||||||
redoStack: [],
|
redoStack: [],
|
||||||
@@ -1747,15 +1606,18 @@ describe('useVim hook', () => {
|
|||||||
selectionAnchor: null,
|
selectionAnchor: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = textBufferReducer(initialState, {
|
const action = (
|
||||||
type: 'vim_change_to_end_of_line',
|
count
|
||||||
});
|
? { type: actionType, payload: { count } }
|
||||||
|
: { type: actionType }
|
||||||
|
) as TextBufferAction;
|
||||||
|
|
||||||
// Should delete entire line content
|
const result = textBufferReducer(initialState, action);
|
||||||
expect(result.lines).toEqual(['']);
|
|
||||||
expect(result.cursorRow).toBe(0);
|
expect(result.lines).toEqual(expectedLines);
|
||||||
expect(result.cursorCol).toBe(0);
|
expect(result.cursorRow).toBe(expectedCursorRow);
|
||||||
});
|
expect(result.cursorCol).toBe(expectedCursorCol);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user