mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 17:48:56 +01:00
@@ -14,10 +14,10 @@ const CURSOR = '$$CURSOR$$';
|
||||
|
||||
const testFileName = vscode.Uri.file('test.md');
|
||||
|
||||
suite.only('markdown.SmartSelect', () => {
|
||||
suite('markdown.SmartSelect', () => {
|
||||
test('Smart select single word', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(`Hel${CURSOR}lo`);
|
||||
assertNestedRangesEqual(ranges![0], [0, 1]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [0, 0]);
|
||||
});
|
||||
test('Smart select multi-line paragraph', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -26,12 +26,12 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`For example, the[node debug adapter](https://github.com/microsoft/vscode-node-debug) and the [mono debug adapter]`,
|
||||
`(https://github.com/microsoft/vscode-mono-debug) have their own repositories. For a complete list, please visit the [Related Projects](https://github.com/microsoft/vscode/wiki/Related-Projects) page on our [wiki](https://github.com/microsoft/vscode/wiki).`
|
||||
));
|
||||
assertNestedRangesEqual(ranges![0], [0, 3]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [0, 2]);
|
||||
});
|
||||
test('Smart select paragraph', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(`Many of the core components and extensions to ${CURSOR}VS Code live in their own repositories on GitHub. For example, the [node debug adapter](https://github.com/microsoft/vscode-node-debug) and the [mono debug adapter](https://github.com/microsoft/vscode-mono-debug) have their own repositories. For a complete list, please visit the [Related Projects](https://github.com/microsoft/vscode/wiki/Related-Projects) page on our [wiki](https://github.com/microsoft/vscode/wiki).`);
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [0, 1]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [0, 0]);
|
||||
});
|
||||
test('Smart select html block', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -40,7 +40,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`${CURSOR}<img alt="VS Code in action" src="https://user-images.githubusercontent.com/1487073/58344409-70473b80-7e0a-11e9-8570-b2efc6f8fa44.png">`,
|
||||
`</p>`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [0, 3]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [0, 2]);
|
||||
});
|
||||
test('Smart select header on header line', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -48,7 +48,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`# Header${CURSOR}`,
|
||||
`Hello`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [0, 1]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [0, 1]);
|
||||
|
||||
});
|
||||
test('Smart select single word w grandparent header on text line', async () => {
|
||||
@@ -59,7 +59,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`${CURSOR}Hello`
|
||||
));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [2, 2], [1, 2]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [2, 2], [1, 2]);
|
||||
});
|
||||
test('Smart select html block w parent header', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -69,7 +69,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`<img alt="VS Code in action" src="https://user-images.githubusercontent.com/1487073/58344409-70473b80-7e0a-11e9-8570-b2efc6f8fa44.png">`,
|
||||
`</p>`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [1, 3], [1, 3], [0, 3]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [1, 1], [1, 3], [0, 3]);
|
||||
});
|
||||
test('Smart select fenced code block', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -78,7 +78,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`a${CURSOR}`,
|
||||
`~~~`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [0, 2]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [0, 2]);
|
||||
});
|
||||
test('Smart select list', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -87,8 +87,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`- ${CURSOR}item 2`,
|
||||
`- item 3`,
|
||||
`- item 4`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [1, 1], [0, 3]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [1, 1], [0, 3]);
|
||||
});
|
||||
test('Smart select list with fenced code block', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -100,7 +99,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`- item 3`,
|
||||
`- item 4`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [1, 3], [0, 5]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [1, 3], [0, 5]);
|
||||
});
|
||||
test('Smart select multi cursor', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -112,8 +111,8 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`- ${CURSOR}item 3`,
|
||||
`- item 4`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [0, 0], [0, 5]);
|
||||
assertNestedRangesEqual(ranges![1], [4, 4], [0, 5]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [0, 0], [0, 5]);
|
||||
assertNestedLineNumbersEqual(ranges![1], [4, 4], [0, 5]);
|
||||
});
|
||||
test('Smart select nested block quotes', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -122,7 +121,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`> item 2`,
|
||||
`>> ${CURSOR}item 3`,
|
||||
`>> item 4`));
|
||||
assertNestedRangesEqual(ranges![0], [2, 4], [0, 4]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [2, 2], [2, 3], [0, 3]);
|
||||
});
|
||||
test('Smart select multi nested block quotes', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -131,8 +130,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`>> item 2`,
|
||||
`>>> ${CURSOR}item 3`,
|
||||
`>>>> item 4`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [2, 3], [2, 4], [1, 4], [0, 4]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [2, 2], [2, 3], [1, 3], [0, 3]);
|
||||
});
|
||||
test('Smart select subheader content', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -143,7 +141,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`${CURSOR}content 2`,
|
||||
`# main header 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [3, 3], [2, 3], [1, 3], [0, 3]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [3, 3], [2, 3], [1, 3], [0, 3]);
|
||||
});
|
||||
test('Smart select subheader line', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -154,7 +152,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`content 2`,
|
||||
`# main header 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [2, 3], [1, 3], [0, 3]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [2, 3], [1, 3], [0, 3]);
|
||||
});
|
||||
test('Smart select blank line', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -165,7 +163,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`content 2`,
|
||||
`# main header 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [1, 3], [0, 3]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [1, 3], [0, 3]);
|
||||
});
|
||||
test('Smart select line between paragraphs', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -174,7 +172,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`${CURSOR}`,
|
||||
`paragraph 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [0, 3]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [0, 2]);
|
||||
});
|
||||
test('Smart select empty document', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(``, [new vscode.Position(0, 0)]);
|
||||
@@ -196,7 +194,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`more content`,
|
||||
`# main header 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [4, 6], [3, 9], [3, 10], [2, 10], [1, 10], [0, 10]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [4, 6], [3, 9], [3, 10], [2, 10], [1, 10], [0, 10]);
|
||||
});
|
||||
test('Smart select list with one element without selecting child subheader', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -209,8 +207,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
``,
|
||||
`content 2`,
|
||||
`# main header 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [2, 3], [1, 3], [1, 6], [0, 6]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [2, 2], [2, 3], [1, 3], [1, 6], [0, 6]);
|
||||
});
|
||||
test('Smart select content under header then subheaders and their content', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -224,7 +221,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`content 2`,
|
||||
`# main header 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [0, 3], [0, 6]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [0, 3], [0, 6]);
|
||||
});
|
||||
test('Smart select last blockquote element under header then subheaders and their content', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -242,7 +239,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`content 2`,
|
||||
`# main header 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [4, 6], [2, 6], [1, 7], [1, 10], [0, 10]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [5, 5], [4, 5], [2, 5], [1, 7], [1, 10], [0, 10]);
|
||||
});
|
||||
test('Smart select content of subheader then subheader then content of main header then main header', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -266,7 +263,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`- content 2`,
|
||||
`content 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [11, 12], [9, 12], [9, 17], [8, 17], [1, 17], [0, 17]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [11, 11], [9, 12], [9, 17], [8, 17], [1, 17], [0, 17]);
|
||||
});
|
||||
test('Smart select last line content of subheader then subheader then content of main header then main header', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -288,9 +285,9 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`- content 2`,
|
||||
`- content 2`,
|
||||
`- content 2`,
|
||||
`${CURSOR}content 2`));
|
||||
`- ${CURSOR}content 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [16, 17], [14, 17], [14, 17], [13, 17], [9, 17], [8, 17], [1, 17], [0, 17]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [17, 17], [14, 17], [13, 17], [9, 17], [8, 17], [1, 17], [0, 17]);
|
||||
});
|
||||
test('Smart select last line content after content of subheader then subheader then content of main header then main header', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -312,9 +309,9 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`- content 2`,
|
||||
`- content 2`,
|
||||
`- content 2`,
|
||||
`content 2${CURSOR}`));
|
||||
`- content 2${CURSOR}`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [16, 17], [14, 17], [14, 17], [13, 17], [9, 17], [8, 17], [1, 17], [0, 17]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [17, 17], [14, 17], [13, 17], [9, 17], [8, 17], [1, 17], [0, 17]);
|
||||
});
|
||||
test('Smart select fenced code block then list then rest of content', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -338,7 +335,7 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`- content 2`,
|
||||
`- content 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [9, 11], [8, 12], [7, 17], [1, 17], [0, 17]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [9, 11], [8, 12], [7, 17], [1, 17], [0, 17]);
|
||||
});
|
||||
test('Smart select fenced code block then list then rest of content on fenced line', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
@@ -362,15 +359,70 @@ suite.only('markdown.SmartSelect', () => {
|
||||
`- content 2`,
|
||||
`- content 2`));
|
||||
|
||||
assertNestedRangesEqual(ranges![0], [8, 12], [7, 17], [1, 17], [0, 17]);
|
||||
assertNestedLineNumbersEqual(ranges![0], [8, 12], [7, 17], [1, 17], [0, 17]);
|
||||
});
|
||||
test('Smart select without multiple ranges', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
joinLines(
|
||||
`# main header 1`,
|
||||
``,
|
||||
``,
|
||||
`- ${CURSOR}paragraph`,
|
||||
`- content`));
|
||||
|
||||
assertNestedLineNumbersEqual(ranges![0], [3, 3], [3, 4], [1, 4], [0, 4]);
|
||||
});
|
||||
test('Smart select on second level of a list', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
joinLines(
|
||||
`* level 0`,
|
||||
` * level 1`,
|
||||
` * level 1`,
|
||||
` * level 2`,
|
||||
` * level 1`,
|
||||
` * level ${CURSOR}1`,
|
||||
`* level 0`));
|
||||
|
||||
assertNestedLineNumbersEqual(ranges![0], [5, 5], [1, 5], [0, 5], [0, 6]);
|
||||
});
|
||||
test('Smart select on third level of a list', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
joinLines(
|
||||
`* level 0`,
|
||||
` * level 1`,
|
||||
` * level 1`,
|
||||
` * level ${CURSOR}2`,
|
||||
` * level 2`,
|
||||
` * level 1`,
|
||||
` * level 1`,
|
||||
`* level 0`));
|
||||
assertNestedLineNumbersEqual(ranges![0], [3, 3], [3, 4], [2, 4], [1, 6], [0, 6], [0, 7]);
|
||||
});
|
||||
test('Smart select level 2 then level 1', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
joinLines(
|
||||
`* level 1`,
|
||||
` * level ${CURSOR}2`,
|
||||
` * level 2`,
|
||||
`* level 1`));
|
||||
assertNestedLineNumbersEqual(ranges![0], [1, 1], [1, 2], [0, 2], [0, 3]);
|
||||
});
|
||||
test('Smart select last list item', async () => {
|
||||
const ranges = await getSelectionRangesForDocument(
|
||||
joinLines(
|
||||
`- level 1`,
|
||||
`- level 2`,
|
||||
`- level 2`,
|
||||
`- level ${CURSOR}1`));
|
||||
assertNestedLineNumbersEqual(ranges![0], [3, 3], [0, 3]);
|
||||
});
|
||||
});
|
||||
|
||||
function assertNestedRangesEqual(range: vscode.SelectionRange, ...expectedRanges: [number, number][]) {
|
||||
function assertNestedLineNumbersEqual(range: vscode.SelectionRange, ...expectedRanges: [number, number][]) {
|
||||
const lineage = getLineage(range);
|
||||
assert.strictEqual(lineage.length, expectedRanges.length, `expected depth: ${expectedRanges.length}, but was ${lineage.length}`);
|
||||
for (let i = 0; i < lineage.length; i++) {
|
||||
assertRangesEqual(lineage[i], expectedRanges[i][0], expectedRanges[i][1], `parent at a depth of ${i}`);
|
||||
assertLineNumbersEqual(lineage[i], expectedRanges[i][0], expectedRanges[i][1], `parent at a depth of ${i}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +436,7 @@ function getLineage(range: vscode.SelectionRange): vscode.SelectionRange[] {
|
||||
return result;
|
||||
}
|
||||
|
||||
function assertRangesEqual(selectionRange: vscode.SelectionRange, startLine: number, endLine: number, message: string) {
|
||||
function assertLineNumbersEqual(selectionRange: vscode.SelectionRange, startLine: number, endLine: number, message: string) {
|
||||
assert.strictEqual(selectionRange.range.start.line, startLine, `failed on start line ${message}`);
|
||||
assert.strictEqual(selectionRange.range.end.line, endLine, `failed on end line ${message}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user