提交 6030187b 编写于 作者: R Ramya Achutha Rao

Tests for Emmet Balance In/Out

上级 0a4fa1e7
......@@ -59,15 +59,18 @@ function getRangeToBalanceOut(document: vscode.TextDocument, selection: vscode.S
}
function getRangeToBalanceIn(document: vscode.TextDocument, selection: vscode.Selection, rootNode: HtmlNode): vscode.Selection {
let nodeToBalance = <HtmlNode>getNode(rootNode, selection.start);
let nodeToBalance = <HtmlNode>getNode(rootNode, selection.start, true);
if (!nodeToBalance) {
return;
}
if (selection.start.isEqual(nodeToBalance.start)
&& selection.end.isEqual(nodeToBalance.end)
&& nodeToBalance.close) {
return new vscode.Selection(nodeToBalance.open.end, nodeToBalance.close.start);
}
if (!nodeToBalance.firstChild) {
if (nodeToBalance.close) {
return new vscode.Selection(nodeToBalance.open.end, nodeToBalance.close.start);
}
return;
}
......
......@@ -8,6 +8,7 @@ import { Selection } from 'vscode';
import { withRandomFileEditor, closeAllEditors } from './testUtils';
import { fetchEditPoint } from '../editPoint';
import { fetchSelectItem } from '../selectItem';
import { balanceOut, balanceIn } from '../balance';
suite('Tests for Next/Previous Select/Edit point actions', () => {
teardown(closeAllEditors);
......@@ -48,8 +49,8 @@ suite('Tests for Next/Previous Select/Edit point actions', () => {
</div>
<div class="header">
<ul class="nav main">
<li class="item">Item 1</li>
<li class="item">Item 2</li>
<li class="item1">Item 1</li>
<li class="item2">Item 2</li>
</ul>
</div>
</body>
......@@ -63,13 +64,13 @@ suite('Tests for Next/Previous Select/Edit point actions', () => {
let expectedNextEditPoints: [number, number][] = [[4, 16], [6, 8], [10, 2], [20, 0]];
expectedNextEditPoints.forEach(([line, col]) => {
fetchEditPoint('next');
testSelection(editor.selection, line, col);
testSelection(editor.selection, col, line);
});
let expectedPrevEditPoints = [[10, 2], [6, 8], [4, 16], [0, 0]];
expectedPrevEditPoints.forEach(([line, col]) => {
fetchEditPoint('prev');
testSelection(editor.selection, line, col);
testSelection(editor.selection, col, line);
});
return Promise.resolve();
......@@ -98,13 +99,13 @@ suite('Tests for Next/Previous Select/Edit point actions', () => {
];
expectedNextItemPoints.forEach(([line, colstart, colend]) => {
fetchSelectItem('next');
testSelection(editor.selection, line, colstart, colend);
testSelection(editor.selection, colstart, line, colend);
});
editor.selections = [new Selection(6, 15, 6, 15)];
expectedNextItemPoints.reverse().forEach(([line, colstart, colend]) => {
fetchSelectItem('prev');
testSelection(editor.selection, line, colstart, colend);
testSelection(editor.selection, colstart, line, colend);
});
return Promise.resolve();
......@@ -129,13 +130,13 @@ suite('Tests for Next/Previous Select/Edit point actions', () => {
];
expectedNextItemPoints.forEach(([line, colstart, colend]) => {
fetchSelectItem('next');
testSelection(editor.selection, line, colstart, colend);
testSelection(editor.selection, colstart, line, colend);
});
editor.selections = [new Selection(9, 0, 9, 0)];
expectedNextItemPoints.reverse().forEach(([line, colstart, colend]) => {
fetchSelectItem('prev');
testSelection(editor.selection, line, colstart, colend);
testSelection(editor.selection, colstart, line, colend);
});
return Promise.resolve();
......@@ -160,13 +161,49 @@ suite('Tests for Next/Previous Select/Edit point actions', () => {
];
expectedNextItemPoints.forEach(([line, colstart, colend]) => {
fetchSelectItem('next');
testSelection(editor.selection, line, colstart, colend);
testSelection(editor.selection, colstart, line, colend);
});
editor.selections = [new Selection(8, 0, 8, 0)];
expectedNextItemPoints.reverse().forEach(([line, colstart, colend]) => {
fetchSelectItem('prev');
testSelection(editor.selection, line, colstart, colend);
testSelection(editor.selection, colstart, line, colend);
});
return Promise.resolve();
});
});
test('Emmet Balance Out in html file', function (): any {
return withRandomFileEditor(htmlContents, 'html', (editor, doc) => {
editor.selections = [new Selection(14, 6, 14, 10)];
let expectedBalanceOutRanges: [number, number, number, number][] = [
[14, 3, 14, 32], // <li class="item1">Item 1</li>
[13, 23, 16, 2], // inner contents of <ul class="nav main">
[13, 2, 16, 7], // outer contents of <ul class="nav main">
[12, 21, 17, 1], // inner contents of <div class="header">
[12, 1, 17, 7], // outer contents of <div class="header">
[8, 6, 18, 0], // inner contents of <body>
[8, 0, 18, 7], // outer contents of <body>
[2, 16, 19, 0], // inner contents of <html>
[2, 0, 19, 7], // outer contents of <html>
];
expectedBalanceOutRanges.forEach(([linestart, colstart, lineend, colend]) => {
balanceOut();
testSelection(editor.selection, colstart, linestart, colend, lineend);
});
editor.selections = [new Selection(12, 7, 12, 7)];
let expectedBalanceInRanges: [number, number, number, number][] = [
[13, 2, 16, 7], // outer contents of <ul class="nav main">
[13, 23, 16, 2], // inner contents of <ul class="nav main">
[14, 3, 14, 32], // <li class="item1">Item 1</li>
[14, 21, 14, 27] // Item 1
];
expectedBalanceInRanges.forEach(([linestart, colstart, lineend, colend]) => {
balanceIn();
testSelection(editor.selection, colstart, linestart, colend, lineend);
});
return Promise.resolve();
......@@ -175,11 +212,16 @@ suite('Tests for Next/Previous Select/Edit point actions', () => {
});
function testSelection(selection: Selection, line: number, startChar: number, endChar?: number) {
assert.equal(selection.isSingleLine, true);
assert.equal(selection.anchor.line, line);
function testSelection(selection: Selection, startChar: number, startline: number, endChar?: number, endLine?: number) {
assert.equal(selection.anchor.line, startline);
assert.equal(selection.anchor.character, startChar);
if (!endChar) {
if (!endLine && endLine !== 0) {
assert.equal(selection.isSingleLine, true);
} else {
assert.equal(selection.active.line, endLine);
}
if (!endChar && endChar !== 0) {
assert.equal(selection.isEmpty, true);
} else {
assert.equal(selection.active.character, endChar);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册