summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/editor.test.ts
diff options
context:
space:
mode:
authoryuki yano <[email protected]>2025-06-30 02:25:22 +0900
committerGitHub <[email protected]>2025-06-29 17:25:22 +0000
commitc860dac2333320d53a9bb9054efe460b8798fc2b (patch)
tree2d136b12cc773b971a7ba46de540a6872a38da3d /packages/core/src/utils/editor.test.ts
parent87d4fc05609aa2289575fea73372f6fab4281bcd (diff)
feat: add Neovim editor support (#1448)
Diffstat (limited to 'packages/core/src/utils/editor.test.ts')
-rw-r--r--packages/core/src/utils/editor.test.ts76
1 files changed, 51 insertions, 25 deletions
diff --git a/packages/core/src/utils/editor.test.ts b/packages/core/src/utils/editor.test.ts
index 09bd496f..382e5e18 100644
--- a/packages/core/src/utils/editor.test.ts
+++ b/packages/core/src/utils/editor.test.ts
@@ -60,6 +60,7 @@ describe('editor utils', () => {
{ editor: 'windsurf', command: 'windsurf', win32Command: 'windsurf' },
{ editor: 'cursor', command: 'cursor', win32Command: 'cursor' },
{ editor: 'vim', command: 'vim', win32Command: 'vim' },
+ { editor: 'neovim', command: 'nvim', win32Command: 'nvim' },
{ editor: 'zed', command: 'zed', win32Command: 'zed' },
];
@@ -139,31 +140,41 @@ describe('editor utils', () => {
});
}
- it('should return the correct command for vim', () => {
- const command = getDiffCommand('old.txt', 'new.txt', 'vim');
- expect(command).toEqual({
- command: 'vim',
- args: [
- '-d',
- '-i',
- 'NONE',
- '-c',
- 'wincmd h | set readonly | wincmd l',
- '-c',
- 'highlight DiffAdd cterm=bold ctermbg=22 guibg=#005f00 | highlight DiffChange cterm=bold ctermbg=24 guibg=#005f87 | highlight DiffText ctermbg=21 guibg=#0000af | highlight DiffDelete ctermbg=52 guibg=#5f0000',
- '-c',
- 'set showtabline=2 | set tabline=[Instructions]\\ :wqa(save\\ &\\ quit)\\ \\|\\ i/esc(toggle\\ edit\\ mode)',
- '-c',
- 'wincmd h | setlocal statusline=OLD\\ FILE',
- '-c',
- 'wincmd l | setlocal statusline=%#StatusBold#NEW\\ FILE\\ :wqa(save\\ &\\ quit)\\ \\|\\ i/esc(toggle\\ edit\\ mode)',
- '-c',
- 'autocmd WinClosed * wqa',
- 'old.txt',
- 'new.txt',
- ],
+ const terminalEditors: Array<{
+ editor: EditorType;
+ command: string;
+ }> = [
+ { editor: 'vim', command: 'vim' },
+ { editor: 'neovim', command: 'nvim' },
+ ];
+
+ for (const { editor, command } of terminalEditors) {
+ it(`should return the correct command for ${editor}`, () => {
+ const diffCommand = getDiffCommand('old.txt', 'new.txt', editor);
+ expect(diffCommand).toEqual({
+ command,
+ args: [
+ '-d',
+ '-i',
+ 'NONE',
+ '-c',
+ 'wincmd h | set readonly | wincmd l',
+ '-c',
+ 'highlight DiffAdd cterm=bold ctermbg=22 guibg=#005f00 | highlight DiffChange cterm=bold ctermbg=24 guibg=#005f87 | highlight DiffText ctermbg=21 guibg=#0000af | highlight DiffDelete ctermbg=52 guibg=#5f0000',
+ '-c',
+ 'set showtabline=2 | set tabline=[Instructions]\\ :wqa(save\\ &\\ quit)\\ \\|\\ i/esc(toggle\\ edit\\ mode)',
+ '-c',
+ 'wincmd h | setlocal statusline=OLD\\ FILE',
+ '-c',
+ 'wincmd l | setlocal statusline=%#StatusBold#NEW\\ FILE\\ :wqa(save\\ &\\ quit)\\ \\|\\ i/esc(toggle\\ edit\\ mode)',
+ '-c',
+ 'autocmd WinClosed * wqa',
+ 'old.txt',
+ 'new.txt',
+ ],
+ });
});
- });
+ }
it('should return null for an unsupported editor', () => {
// @ts-expect-error Testing unsupported editor
@@ -240,7 +251,7 @@ describe('editor utils', () => {
});
}
- const execSyncEditors: EditorType[] = ['vim'];
+ const execSyncEditors: EditorType[] = ['vim', 'neovim'];
for (const editor of execSyncEditors) {
it(`should call execSync for ${editor} on non-windows`, async () => {
Object.defineProperty(process, 'platform', { value: 'linux' });
@@ -293,6 +304,15 @@ describe('editor utils', () => {
expect(allowEditorTypeInSandbox('vim')).toBe(true);
});
+ it('should allow neovim in sandbox mode', () => {
+ process.env.SANDBOX = 'sandbox';
+ expect(allowEditorTypeInSandbox('neovim')).toBe(true);
+ });
+
+ it('should allow neovim when not in sandbox mode', () => {
+ expect(allowEditorTypeInSandbox('neovim')).toBe(true);
+ });
+
const guiEditors: EditorType[] = [
'vscode',
'vscodium',
@@ -348,5 +368,11 @@ describe('editor utils', () => {
process.env.SANDBOX = 'sandbox';
expect(isEditorAvailable('vim')).toBe(true);
});
+
+ it('should return true for neovim when installed and in sandbox mode', () => {
+ (execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/nvim'));
+ process.env.SANDBOX = 'sandbox';
+ expect(isEditorAvailable('neovim')).toBe(true);
+ });
});
});