Merge from vscode 6e530127a1bb8ffbd1bfb77dc680c321dc0d71f5 (#6844)

This commit is contained in:
Anthony Dresser
2019-08-20 21:07:47 -07:00
committed by GitHub
parent 1f00249646
commit ecb80f14f0
221 changed files with 3140 additions and 1552 deletions

View File

@@ -7,6 +7,7 @@ import * as assert from 'assert';
import { StandardTokenType } from 'vs/editor/common/modes';
import { CharacterPairSupport } from 'vs/editor/common/modes/supports/characterPair';
import { TokenText, createFakeScopedLineTokens } from 'vs/editor/test/common/modesTestUtils';
import { StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration';
suite('CharacterPairSupport', () => {
@@ -52,8 +53,21 @@ suite('CharacterPairSupport', () => {
assert.deepEqual(characaterPairSupport.getSurroundingPairs(), []);
});
function findAutoClosingPair(characterPairSupport: CharacterPairSupport, character: string): StandardAutoClosingPairConditional | null {
for (const autoClosingPair of characterPairSupport.getAutoClosingPairs()) {
if (autoClosingPair.open === character) {
return autoClosingPair;
}
}
return null;
}
function testShouldAutoClose(characterPairSupport: CharacterPairSupport, line: TokenText[], character: string, column: number): boolean {
return characterPairSupport.shouldAutoClosePair(character, createFakeScopedLineTokens(line), column);
const autoClosingPair = findAutoClosingPair(characterPairSupport, character);
if (!autoClosingPair) {
return false;
}
return CharacterPairSupport.shouldAutoClosePair(autoClosingPair, createFakeScopedLineTokens(line), column);
}
test('shouldAutoClosePair in empty line', () => {

View File

@@ -21,86 +21,20 @@ suite('Editor Modes - Auto Indentation', () => {
assert.deepEqual(actual, null);
}
function testAppends(electricCharacterSupport: BracketElectricCharacterSupport, line: TokenText[], character: string, offset: number, appendText: string): void {
let actual = _testOnElectricCharacter(electricCharacterSupport, line, character, offset);
assert.deepEqual(actual, { appendText: appendText });
}
function testMatchBracket(electricCharacterSupport: BracketElectricCharacterSupport, line: TokenText[], character: string, offset: number, matchOpenBracket: string): void {
let actual = _testOnElectricCharacter(electricCharacterSupport, line, character, offset);
assert.deepEqual(actual, { matchOpenBracket: matchOpenBracket });
}
test('Doc comments', () => {
let brackets = new BracketElectricCharacterSupport(null, [{ open: '/**', close: ' */' }], null);
testAppends(brackets, [
{ text: '/*', type: StandardTokenType.Other },
], '*', 3, ' */');
testDoesNothing(brackets, [
{ text: '/*', type: StandardTokenType.Other },
{ text: ' ', type: StandardTokenType.Other },
{ text: '*/', type: StandardTokenType.Other },
], '*', 3);
});
test('getElectricCharacters uses all sources and dedups', () => {
let sup = new BracketElectricCharacterSupport(
new RichEditBrackets(fakeLanguageIdentifier, [
['{', '}'],
['(', ')']
]), [
{ open: '{', close: '}', notIn: ['string', 'comment'] },
{ open: '"', close: '"', notIn: ['string', 'comment'] },
{ open: 'begin', close: 'end', notIn: ['string'] }
],
{ docComment: { open: '/**', close: ' */' } }
])
);
assert.deepEqual(sup.getElectricCharacters(), ['}', ')', 'n', '*']);
});
test('auto-close', () => {
let sup = new BracketElectricCharacterSupport(
new RichEditBrackets(fakeLanguageIdentifier, [
['{', '}'],
['(', ')']
]), [
{ open: '{', close: '}', notIn: ['string', 'comment'] },
{ open: '"', close: '"', notIn: ['string', 'comment'] },
{ open: 'begin', close: 'end', notIn: ['string'] }
],
{ docComment: { open: '/**', close: ' */' } }
);
testDoesNothing(sup, [], 'a', 0);
testDoesNothing(sup, [{ text: 'egi', type: StandardTokenType.Other }], 'b', 1);
testDoesNothing(sup, [{ text: 'bgi', type: StandardTokenType.Other }], 'e', 2);
testDoesNothing(sup, [{ text: 'bei', type: StandardTokenType.Other }], 'g', 3);
testDoesNothing(sup, [{ text: 'beg', type: StandardTokenType.Other }], 'i', 4);
testDoesNothing(sup, [{ text: 'egin', type: StandardTokenType.Other }], 'b', 1);
testDoesNothing(sup, [{ text: 'bgin', type: StandardTokenType.Other }], 'e', 2);
testDoesNothing(sup, [{ text: 'bein', type: StandardTokenType.Other }], 'g', 3);
testDoesNothing(sup, [{ text: 'begn', type: StandardTokenType.Other }], 'i', 4);
testAppends(sup, [{ text: 'begi', type: StandardTokenType.Other }], 'n', 5, 'end');
testDoesNothing(sup, [{ text: '3gin', type: StandardTokenType.Other }], 'b', 1);
testDoesNothing(sup, [{ text: 'bgin', type: StandardTokenType.Other }], '3', 2);
testDoesNothing(sup, [{ text: 'b3in', type: StandardTokenType.Other }], 'g', 3);
testDoesNothing(sup, [{ text: 'b3gn', type: StandardTokenType.Other }], 'i', 4);
testDoesNothing(sup, [{ text: 'b3gi', type: StandardTokenType.Other }], 'n', 5);
testDoesNothing(sup, [{ text: 'begi', type: StandardTokenType.String }], 'n', 5);
testAppends(sup, [{ text: '"', type: StandardTokenType.String }, { text: 'begi', type: StandardTokenType.Other }], 'n', 6, 'end');
testDoesNothing(sup, [{ text: '"', type: StandardTokenType.String }, { text: 'begi', type: StandardTokenType.String }], 'n', 6);
testAppends(sup, [{ text: '/*', type: StandardTokenType.String }], '*', 3, ' */');
testDoesNothing(sup, [{ text: 'begi', type: StandardTokenType.Other }, { text: 'end', type: StandardTokenType.Other }], 'n', 5);
assert.deepEqual(sup.getElectricCharacters(), ['}', ')']);
});
test('matchOpenBracket', () => {
@@ -108,12 +42,7 @@ suite('Editor Modes - Auto Indentation', () => {
new RichEditBrackets(fakeLanguageIdentifier, [
['{', '}'],
['(', ')']
]), [
{ open: '{', close: '}', notIn: ['string', 'comment'] },
{ open: '"', close: '"', notIn: ['string', 'comment'] },
{ open: 'begin', close: 'end', notIn: ['string'] }
],
{ docComment: { open: '/**', close: ' */' } }
])
);
testDoesNothing(sup, [{ text: '\t{', type: StandardTokenType.Other }], '\t', 1);