Vim/test/motionIncSearch.test.ts
Adam Smith 3499afc91c
Improve incremental search (#7224)
- Highlight current match with a different configurable highlight color
- Support `<C-g>`/`<C-t>` to cycle through matches
- Highlight zero-length matches
- Fix a few other edge cases (such as when searching backward or with `^`/`$` with CLRF line endings)

Fixes #7212, fixes #4837
2021-12-31 17:27:38 -05:00

101 lines
2.8 KiB
TypeScript

import { Configuration } from './testConfiguration';
import { newTest } from './testSimplifier';
import { cleanUpWorkspace, setupWorkspace } from './testUtils';
suite('incsearch motion', () => {
setup(async () => {
const configuration = new Configuration();
configuration.wrapscan = true;
configuration.incsearch = true;
await setupWorkspace(configuration);
});
teardown(cleanUpWorkspace);
suite('<C-g>', () => {
newTest({
title: '<C-g> advances current match forward during forward search.',
start: ['|one two two two'],
keysPressed: '/two<C-g>\n',
end: ['one two |two two'],
});
newTest({
title: '<C-g> advances current match forward during backward search.',
start: ['one two |two two'],
keysPressed: '?two<C-g>\n',
end: ['one two |two two'],
});
newTest({
title: '<C-g> advances current match forward by search count',
start: ['|one two two two two two two'],
keysPressed: '3/tw<C-g>\n',
end: ['one two two two two two |two'],
});
newTest({
title: '<C-g> wraps to top of buffer when wrapscan is true',
start: ['|one two two two'],
keysPressed: '/tw<C-g><C-g><C-g>\n',
end: ['one |two two two'],
});
newTest({
title: '<C-g> stops at last match in buffer when wrapscan is false',
config: { wrapscan: false },
start: ['|one two two two'],
keysPressed: '/tw<C-g><C-g><C-g>\n',
end: ['one two two |two'],
});
newTest({
title:
'<C-g> during search with count stops at last reachable match in buffer when wrapscan is false',
config: { wrapscan: false },
start: ['|one two two two'],
keysPressed: '2/tw<C-g><C-g>\n',
end: ['one two |two two'],
});
});
suite('<C-t>', () => {
newTest({
title: '<C-t> moves backward during forward search.',
start: ['one |two two two'],
keysPressed: '/two<C-t>\n',
end: ['one |two two two'],
});
newTest({
title: '<C-t> moves backward during backward search.',
start: ['one two two |two'],
keysPressed: '?two<C-t>\n',
end: ['one |two two two'],
});
newTest({
title: '<C-t> wraps to last match in buffer with wrapscan',
start: ['one two |two two'],
keysPressed: '/tw<C-t><C-t><C-t>\n',
end: ['one two two |two'],
});
newTest({
title: '<C-t> stays at first match in buffer with nowrapscan',
config: { wrapscan: false },
start: ['one two |two two'],
keysPressed: '/tw<C-t><C-t><C-t>\n',
end: ['one |two two two'],
});
newTest({
title:
'<C-t> during search with count stays at first reachable match in buffer with nowrapscan',
config: { wrapscan: false },
start: ['one two |two two'],
keysPressed: '2/tw<C-t><C-t>\n',
end: ['one two |two two'],
});
});
});