From 23da1518a676069cffacb0535ecf00e29511fd54 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Wed, 20 Jun 2018 17:35:55 +0200 Subject: [PATCH] Add test for snippet transform with indention. --- .../snippet/test/snippetSession.test.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/vs/editor/contrib/snippet/test/snippetSession.test.ts b/src/vs/editor/contrib/snippet/test/snippetSession.test.ts index ed255770f69..8093aa82221 100644 --- a/src/vs/editor/contrib/snippet/test/snippetSession.test.ts +++ b/src/vs/editor/contrib/snippet/test/snippetSession.test.ts @@ -486,6 +486,46 @@ suite('SnippetSession', function () { assertSelections(editor, new Selection(2, 1, 2, 1)); }); + test('snippets, transform with indent', function () { + const snippet = [ + 'private readonly ${1} = new Emitter<$2>();', + 'readonly ${1/^_(.*)/$1/}: Event<$2> = this.$1.event;', + '$0' + ].join('\n'); + const expected = [ + '{', + '\tprivate readonly _prop = new Emitter();', + '\treadonly prop: Event = this._prop.event;', + '\t', + '}' + ].join('\n'); + const base = [ + '{', + '\t', + '}' + ].join('\n'); + + editor.getModel().setValue(base); + editor.getModel().updateOptions({ insertSpaces: false }); + editor.setSelection(new Selection(2, 2, 2, 2)); + + const session = new SnippetSession(editor, snippet); + session.insert(); + + assertSelections(editor, new Selection(2, 19, 2, 19), new Selection(3, 11, 3, 11), new Selection(3, 28, 3, 28)); + editor.trigger('test', 'type', { text: '_prop' }); + session.next(); + + assertSelections(editor, new Selection(2, 39, 2, 39), new Selection(3, 23, 3, 23)); + editor.trigger('test', 'type', { text: 'string' }); + session.next(); + + assert.equal(model.getValue(), expected); + assert.equal(session.isAtLastPlaceholder, true); + assertSelections(editor, new Selection(4, 2, 4, 2)); + + }); + test('snippets, transform example hit if', function () { editor.getModel().setValue(''); editor.setSelection(new Selection(1, 1, 1, 1));