Merge pull request #17628 from joelday/master

Adding an overload to TextEditor.edit for insertion of a SnippetString
This commit is contained in:
Johannes Rieken
2017-01-20 10:52:33 +01:00
committed by GitHub
8 changed files with 104 additions and 9 deletions

View File

@@ -6,7 +6,7 @@
'use strict';
import * as assert from 'assert';
import { workspace, window, Position, Range, commands, TextEditor, TextDocument, TextEditorCursorStyle, TextEditorLineNumbersStyle } from 'vscode';
import { workspace, window, Position, Range, commands, TextEditor, TextDocument, TextEditorCursorStyle, TextEditorLineNumbersStyle, SnippetString, Selection } from 'vscode';
import { createRandomFile, deleteFile, cleanUp } from './utils';
suite('editor tests', () => {
@@ -33,6 +33,40 @@ suite('editor tests', () => {
});
}
test('insert snippet', () => {
const snippetString = new SnippetString()
.appendText('This is a ')
.appendTabstop()
.appendPlaceholder('placeholder')
.appendText(' snippet');
return withRandomFileEditor('', (editor, doc) => {
return editor.edit(snippetString).then(inserted => {
assert.ok(inserted);
assert.equal(doc.getText(), 'This is a placeholder snippet');
assert.ok(doc.isDirty);
});
});
});
test('insert snippet with replacement', () => {
const snippetString = new SnippetString()
.appendText('has been');
return withRandomFileEditor('This will be replaced', (editor, doc) => {
editor.selection = new Selection(
new Position(0, 5),
new Position(0, 12)
);
return editor.edit(snippetString).then(inserted => {
assert.ok(inserted);
assert.equal(doc.getText(), 'This has been replaced');
assert.ok(doc.isDirty);
});
});
});
test('make edit', () => {
return withRandomFileEditor('', (editor, doc) => {
return editor.edit((builder) => {