From 6b702872e7dfaa28b83a9a2af68ac313644d7461 Mon Sep 17 00:00:00 2001 From: Philip Mateescu Date: Sun, 13 Aug 2017 00:38:56 -0500 Subject: [PATCH] Makes all tests pass on Windows (#1939) * appveyor config v1 * typo * choco failing - getting more info * force install? * ignore dependencies * Dot at the end makes it more obvious what the whole value is * reducing verbosity * fixed read shell command test #1914 special case for win32 + neovim * forgot to remove .only * taking care of the '\r' dangling on lines on win32 #1914 * \\n doesn't translate to new-line on Windows. \\r\\n does fixing failed test 4 of #1914 * prettified the code --- appveyor.yml | 16 ++++++++++++++++ src/neovim/nvimUtil.ts | 10 +++++++++- test/mode/modeNormal.test.ts | 5 +++-- test/testUtils.ts | 7 +++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..9a3a1113 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,16 @@ +environment: + node_version: "6.11.1" + PATH: c:\tools\neovim\Neovim\bin;$(PATH) + +install: + - ps: Install-Product node $env:node_version + - choco install neovim --pre -fy --ignoredependencies + - npm install -g gulp + - npm install + +build_script: + - gulp + +test_script: + - nvim --version + - npm test --silent \ No newline at end of file diff --git a/src/neovim/nvimUtil.ts b/src/neovim/nvimUtil.ts index dd9fb705..d9fca49b 100644 --- a/src/neovim/nvimUtil.ts +++ b/src/neovim/nvimUtil.ts @@ -76,6 +76,12 @@ export class Neovim { static async syncVimToVs(vimState: VimState) { const nvim = vimState.nvim; const buf = await nvim.getCurrentBuf(); + const lines = await buf.getLines(0, -1, false); + + // one Windows, lines that went to nvim and back have a '\r' at the end, + // which causes the issues exhibited in #1914 + const fixedLines = + process.platform === 'win32' ? lines.map((line, index) => line.replace(/\r$/, '')) : lines; await TextEditor.replace( new vscode.Range( @@ -84,9 +90,11 @@ export class Neovim { TextEditor.getLineCount() - 1, TextEditor.getLineMaxColumn(TextEditor.getLineCount() - 1) ), - (await buf.getLines(0, -1, false)).join('\n') + fixedLines.join('\n') ); + console.log(`${lines.length} lines in nvime but ${TextEditor.getLineCount()} in editor.`); + let [row, character] = ((await nvim.callFunction('getpos', ['.'])) as Array).slice( 1, 3 diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 0cbdba90..36a9031f 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -3,6 +3,7 @@ import { setTextEditorOptions, cleanUpWorkspace, assertEqual, + crossPlatformIt, } from './../testUtils'; import { ModeName } from '../../src/mode/mode'; import { ModeHandler } from '../../src/mode/modeHandler'; @@ -1485,14 +1486,14 @@ suite('Mode Normal', () => { newTest({ title: '/ can search with newline', start: ['|asdf', '__asdf', 'asdf'], - keysPressed: '/\\nasdf\n', + keysPressed: crossPlatformIt('/\\nasdf\n'), end: ['asdf', '__asd|f', 'asdf'], }); newTest({ title: '/ can search through multiple newlines', start: ['|asdf', '__asdf', 'asdf', 'abc', ' abc'], - keysPressed: '/asdf\\nasdf\\nabc\n', + keysPressed: crossPlatformIt('/asdf\\nasdf\\nabc\n'), end: ['asdf', '__|asdf', 'asdf', 'abc', ' abc'], }); diff --git a/test/testUtils.ts b/test/testUtils.ts index 19048883..0d0cf6f0 100644 --- a/test/testUtils.ts +++ b/test/testUtils.ts @@ -96,3 +96,10 @@ export function setTextEditorOptions(tabSize: number, insertSpaces: boolean): vo options.insertSpaces = insertSpaces; vscode.window.activeTextEditor!.options = options; } + +export function crossPlatformIt(text: string): string { + if (process.platform === 'win32') { + return text.replace(/\\n/g, '\\r\\n'); + } + return text; +}