提交 7a0f65be 编写于 作者: R Ramya Achutha Rao

Tests for Remove, Split, Join and Match tags

上级 bf634bf4
......@@ -36,7 +36,7 @@ export function activate(context: vscode.ExtensionContext) {
}));
context.subscriptions.push(vscode.commands.registerCommand('emmet.removeTag', () => {
removeTag();
return removeTag();
}));
context.subscriptions.push(vscode.commands.registerCommand('emmet.updateTag', (inputTag) => {
......@@ -61,7 +61,7 @@ export function activate(context: vscode.ExtensionContext) {
}));
context.subscriptions.push(vscode.commands.registerCommand('emmet.splitJoinTag', () => {
splitJoinTag();
return splitJoinTag();
}));
context.subscriptions.push(vscode.commands.registerCommand('emmet.mergeLines', () => {
......
......@@ -28,7 +28,7 @@ export function removeTag() {
rangesToRemove = rangesToRemove.concat(getRangeToRemove(editor, rootNode, selection, indentInSpaces));
});
editor.edit(editBuilder => {
return editor.edit(editBuilder => {
rangesToRemove.forEach(range => {
editBuilder.replace(range, '');
});
......@@ -48,9 +48,6 @@ function getRangeToRemove(editor: vscode.TextEditor, rootNode: HtmlNode, selecti
closeRange = new vscode.Range(nodeToUpdate.close.start, nodeToUpdate.close.end);
}
if (!openRange.contains(selection.start) && !closeRange.contains(selection.start)) {
return [];
}
let ranges = [openRange];
if (closeRange) {
for (let i = openRange.start.line + 1; i <= closeRange.start.line; i++) {
......
......@@ -18,7 +18,7 @@ export function splitJoinTag() {
return;
}
editor.edit(editBuilder => {
return editor.edit(editBuilder => {
editor.selections.reverse().forEach(selection => {
let [rangeToReplace, textToReplaceWith] = getRangesToReplace(editor.document, selection, rootNode);
if (rangeToReplace && textToReplaceWith) {
......
......@@ -7,34 +7,36 @@ import * as assert from 'assert';
import { Selection, commands } from 'vscode';
import { withRandomFileEditor, closeAllEditors } from './testUtils';
suite('Tests for Emmet: Update Tag', () => {
suite('Tests for Emmet actions on html tags', () => {
teardown(closeAllEditors);
const contents = `
<div>
<div class="hello">
<ul>
<li><span>Hello</span></li>
<li><span>There</span></li>
<div><li><span>Bye</span></li></div>
</ul>
<span/>
</div>
`;
/* test('update tag with multiple cursors', () => {
test('update tag with multiple cursors', () => {
const expectedContents = `
<div>
<div class="hello">
<ul>
<li><section>Hello</section></li>
<section><span>There</span></section>
<section><li><span>Bye</span></li></section>
</ul>
<span/>
</div>
`;
return withRandomFileEditor(contents, (editor, doc) => {
return withRandomFileEditor(contents, 'html', (editor, doc) => {
editor.selections = [
new Selection(3, 17, 3, 17), // cursor inside tags
new Selection(4, 14, 4, 14), // cursor inside opening tag
new Selection(5, 47, 5, 47), // cursor inside closing tag
new Selection(4, 5, 4, 5), // cursor inside opening tag
new Selection(5, 35, 5, 35), // cursor inside closing tag
];
return commands.executeCommand('emmet.updateTag', 'section').then(() => {
......@@ -42,5 +44,80 @@ suite('Tests for Emmet: Update Tag', () => {
return Promise.resolve();
});
});
}); */
});
test('remove tag with mutliple cursors', () => {
const expectedContents = `
<div class="hello">
<ul>
<li>Hello</li>
<span>There</span>
<li><span>Bye</span></li>
</ul>
<span/>
</div>
`;
return withRandomFileEditor(contents, 'html', (editor, doc) => {
editor.selections = [
new Selection(3, 17, 3, 17), // cursor inside tags
new Selection(4, 5, 4, 5), // cursor inside opening tag
new Selection(5, 35, 5, 35), // cursor inside closing tag
];
return commands.executeCommand('emmet.removeTag').then(() => {
assert.equal(doc.getText(), expectedContents);
return Promise.resolve();
});
});
});
test('split/join tag with mutliple cursors', () => {
const expectedContents = `
<div class="hello">
<ul>
<li><span/></li>
<li><span>There</span></li>
<div><li><span>Bye</span></li></div>
</ul>
<span></span>
</div>
`;
return withRandomFileEditor(contents, 'html', (editor, doc) => {
editor.selections = [
new Selection(3, 17, 3, 17), // join tag
new Selection(7, 5, 7, 5), // split tag
];
return commands.executeCommand('emmet.splitJoinTag').then(() => {
assert.equal(doc.getText(), expectedContents);
return Promise.resolve();
});
});
});
test('match tag with mutliple cursors', () => {
return withRandomFileEditor(contents, 'html', (editor, doc) => {
editor.selections = [
new Selection(1, 0, 1, 0), // just before tag starts, i.e before <
new Selection(1, 1, 1, 1), // just before tag name starts
new Selection(1, 2, 1, 2), // inside tag name
new Selection(1, 6, 1, 6), // after tag name but before opening tag ends
new Selection(1, 18, 1, 18), // just before opening tag ends
new Selection(1, 19, 1, 19), // just after opening tag ends
];
return commands.executeCommand('emmet.matchTag').then(() => {
editor.selections.forEach(selection => {
assert.equal(selection.active.line, 8);
assert.equal(selection.active.character, 3);
assert.equal(selection.anchor.line, 8);
assert.equal(selection.anchor.character, 3);
});
return Promise.resolve();
});
});
});
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册