Archived
1
0

chore(vscode): update to 1.53.2

These conflicts will be resolved in the following commits. We do it this way so
that PR review is possible.
This commit is contained in:
Joe Previte
2021-02-25 11:27:27 -07:00
1900 changed files with 83066 additions and 64589 deletions

View File

@ -62,13 +62,13 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
return withRandomFileEditor(htmlContents, '.html', (editor, _) => {
editor.selections = [new Selection(1, 5, 1, 5)];
let expectedNextEditPoints: [number, number][] = [[4, 16], [6, 8], [10, 2], [20, 0]];
let expectedNextEditPoints: [number, number][] = [[4, 16], [6, 8], [10, 2], [10, 2]];
expectedNextEditPoints.forEach(([line, col]) => {
fetchEditPoint('next');
testSelection(editor.selection, col, line);
});
let expectedPrevEditPoints = [[10, 2], [6, 8], [4, 16], [0, 0]];
let expectedPrevEditPoints = [[6, 8], [4, 16], [4, 16]];
expectedPrevEditPoints.forEach(([line, col]) => {
fetchEditPoint('prev');
testSelection(editor.selection, col, line);
@ -113,7 +113,7 @@ suite('Tests for Next/Previous Select/Edit point and Balance actions', () => {
});
});
test('Emmet Select Next/Prev item at boundary', function(): any {
test('Emmet Select Next/Prev item at boundary', function (): any {
return withRandomFileEditor(htmlContents, '.html', (editor, _) => {
editor.selections = [new Selection(4, 1, 4, 1)];
@ -365,4 +365,4 @@ function testSelection(selection: Selection, startChar: number, startline: numbe
} else {
assert.equal(selection.active.character, endChar);
}
}
}

View File

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
const path = require('path');
const testRunner = require('vscode/lib/testrunner');
const testRunner = require('../../../../test/integration/electron/testrunner');
const options: any = {
ui: 'tdd',
@ -38,3 +38,34 @@ if (process.env.BUILD_ARTIFACTSTAGINGDIRECTORY) {
testRunner.configure(options);
export = testRunner;
// import * as path from 'path';
// import * as Mocha from 'mocha';
// import * as glob from 'glob';
// export function run(testsRoot: string, cb: (error: any, failures?: number) => void): void {
// // Create the mocha test
// const mocha = new Mocha({
// ui: 'tdd'
// });
// mocha.useColors(true);
// glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
// if (err) {
// return cb(err);
// }
// // Add files to the test suite
// files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
// try {
// // Run the mocha test
// mocha.run(failures => {
// cb(null, failures);
// });
// } catch (err) {
// console.error(err);
// cb(err);
// }
// });
// }

View File

@ -7,15 +7,16 @@ import 'mocha';
import * as assert from 'assert';
import { withRandomFileEditor } from './testUtils';
import * as vscode from 'vscode';
import { parsePartialStylesheet, getNode } from '../util';
import { parsePartialStylesheet, getFlatNode } from '../util';
import { isValidLocationForEmmetAbbreviation } from '../abbreviationActions';
suite('Tests for partial parse of Stylesheets', () => {
function isValid(doc: vscode.TextDocument, range: vscode.Range, syntax: string): boolean {
const rootNode = parsePartialStylesheet(doc, range.end);
const currentNode = getNode(rootNode, range.end, true);
return isValidLocationForEmmetAbbreviation(doc, rootNode, currentNode, syntax, range.end, range);
const endOffset = doc.offsetAt(range.end);
const currentNode = getFlatNode(rootNode, endOffset, true);
return isValidLocationForEmmetAbbreviation(doc, rootNode, currentNode, syntax, endOffset, range);
}
test('Ignore block comment inside rule', function (): any {
@ -257,4 +258,4 @@ ment */{
});
});
});

View File

@ -175,7 +175,7 @@ suite('Tests for Emmet actions on html tags', () => {
<li><span>Hello</span></li>
<li><span>There</span></li>
<div><li><span>Bye</span></li></div>
\t
\t\t
<span/>
</script>
`;

View File

@ -26,7 +26,7 @@ suite('Tests for Toggle Comment action from Emmet (HTML)', () => {
<div><li><span>Bye</span></li></div>
</ul>
<ul>
<!--<li>Previously Commented Node</li>-->
<!-- <li>Previously Commented Node</li> -->
<li>Another Node</li>
</ul>
<span/>
@ -47,24 +47,24 @@ suite('Tests for Toggle Comment action from Emmet (HTML)', () => {
const expectedContents = `
<div class="hello">
<ul>
<li><!--<span>Hello</span>--></li>
<!--<li><span>There</span></li>-->
<!--<div><li><span>Bye</span></li></div>-->
<li><!-- <span>Hello</span> --></li>
<!-- <li><span>There</span></li> -->
<!-- <div><li><span>Bye</span></li></div> -->
</ul>
<!--<ul>
<!-- <ul>
<li>Previously Commented Node</li>
<li>Another Node</li>
</ul>-->
</ul> -->
<span/>
<style>
.boo {
/*margin: 10px;*/
/* margin: 10px; */
padding: 20px;
}
/*.hoo {
/* .hoo {
margin: 10px;
padding: 20px;
}*/
} */
</style>
</div>
`;
@ -89,24 +89,24 @@ suite('Tests for Toggle Comment action from Emmet (HTML)', () => {
const expectedContents = `
<div class="hello">
<ul>
<li><!--<span>Hello</span>--></li>
<!--<li><span>There</span></li>-->
<li><!-- <span>Hello</span> --></li>
<!-- <li><span>There</span></li> -->
<div><li><span>Bye</span></li></div>
</ul>
<!--<ul>
<!-- <ul>
<li>Previously Commented Node</li>
<li>Another Node</li>
</ul>-->
</ul> -->
<span/>
<style>
.boo {
/*margin: 10px;*/
/* margin: 10px; */
padding: 20px;
}
/*.hoo {
/* .hoo {
margin: 10px;
padding: 20px;
}*/
} */
</style>
</div>
`;
@ -130,19 +130,19 @@ suite('Tests for Toggle Comment action from Emmet (HTML)', () => {
const expectedContents = `
<div class="hello">
<ul>
<!--<li><span>Hello</span></li>
<li><span>There</span></li>-->
<!-- <li><span>Hello</span></li>
<li><span>There</span></li> -->
<div><li><span>Bye</span></li></div>
</ul>
<ul>
<!--<li>Previously Commented Node</li>-->
<!-- <li>Previously Commented Node</li> -->
<li>Another Node</li>
</ul>
<span/>
<style>
.boo {
/*margin: 10px;
padding: 20px;*/
/* margin: 10px;
padding: 20px; */
}
.hoo {
margin: 10px;
@ -168,14 +168,14 @@ suite('Tests for Toggle Comment action from Emmet (HTML)', () => {
const expectedContents = `
<div class="hello">
<ul>
<!--<li><span>Hello</span></li>
<li><span>There</span></li>-->
<!-- <li><span>Hello</span></li>
<li><span>There</span></li> -->
<div><li><span>Bye</span></li></div>
</ul>
<!--<ul>
<!-- <ul>
<li>Previously Commented Node</li>
<li>Another Node</li>
</ul>-->
</ul> -->
<span/>
<style>
.boo {
@ -206,16 +206,16 @@ suite('Tests for Toggle Comment action from Emmet (HTML)', () => {
const expectedContents = `
<div class="hello">
<ul>
<li><!--<span>Hello</span>--></li>
<!--<li><span>There</span></li>-->
<li><!-- <span>Hello</span> --></li>
<!-- <li><span>There</span></li> -->
<div><li><span>Bye</span></li></div>
</ul>
<!--<ul>
<!-- <ul>
<li>Previously Commented Node</li>
<li>Another Node</li>
</ul>-->
</ul> -->
<span/>
<!--<style>
<!-- <style>
.boo {
margin: 10px;
padding: 20px;
@ -224,7 +224,7 @@ suite('Tests for Toggle Comment action from Emmet (HTML)', () => {
margin: 10px;
padding: 20px;
}
</style>-->
</style> -->
</div>
`;
return withRandomFileEditor(contents, 'html', (editor, doc) => {
@ -252,16 +252,16 @@ suite('Tests for Toggle Comment action from Emmet (HTML)', () => {
const templateContents = `
<script type="text/template">
<li><span>Hello</span></li>
<li><!--<span>There</span>--></li>
<li><!-- <span>There</span> --></li>
<div><li><span>Bye</span></li></div>
<span/>
</script>
`;
const expectedContents = `
<script type="text/template">
<!--<li><span>Hello</span></li>-->
<!-- <li><span>Hello</span></li> -->
<li><span>There</span></li>
<div><li><!--<span>Bye</span>--></li></div>
<div><li><!-- <span>Bye</span> --></li></div>
<span/>
</script>
`;
@ -298,13 +298,13 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => {
test('toggle comment with multiple cursors, but no selection (CSS)', () => {
const expectedContents = `
.one {
/*margin: 10px;*/
/* margin: 10px; */
padding: 10px;
}
/*.two {
/* .two {
height: 42px;
display: none;
}*/
} */
.three {
width: 42px;
}`;
@ -327,13 +327,13 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => {
test('toggle comment with multiple cursors and whole node selected (CSS)', () => {
const expectedContents = `
.one {
/*margin: 10px;*/
/*padding: 10px;*/
/* margin: 10px; */
/* padding: 10px; */
}
/*.two {
/* .two {
height: 42px;
display: none;
}*/
} */
.three {
width: 42px;
}`;
@ -359,16 +359,16 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => {
test('toggle comment when multiple nodes of same parent are completely under single selection (CSS)', () => {
const expectedContents = `
.one {
/* margin: 10px;
padding: 10px;*/
/* margin: 10px;
padding: 10px; */
}
/*.two {
/* .two {
height: 42px;
display: none;
}
.three {
width: 42px;
}*/`;
} */`;
return withRandomFileEditor(contents, 'css', (editor, doc) => {
editor.selections = [
new Selection(2, 0, 3, 16), // 2 properties completely under a single selection along with whitespace
@ -389,10 +389,10 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => {
const expectedContents = `
.one {
margin: 10px;
/*padding: 10px;
/* padding: 10px;
}
.two {
height: 42px;*/
height: 42px; */
display: none;
}
.three {
@ -417,10 +417,10 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => {
const expectedContents = `
.one {
margin: 10px;
/*padding: 10px;
/* padding: 10px;
}
.two {
height: 42px;*/
height: 42px; */
display: none;
}
.three {
@ -445,10 +445,10 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => {
const expectedContents = `
.one {
margin: 10px;
/*padding: 10px;
/* padding: 10px;
}
.two {
height: 42px;*/
height: 42px; */
display: none;
}
.three {
@ -473,10 +473,10 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => {
const expectedContents = `
.one {
margin: 10px;
/*padding: 10px;
/* padding: 10px;
}
.two {
height: 42px;*/
height: 42px; */
display: none;
}
.three {
@ -500,16 +500,16 @@ suite('Tests for Toggle Comment action from Emmet (CSS)', () => {
test('toggle comment when multiple nodes of same parent are partially under single selection (CSS)', () => {
const expectedContents = `
.one {
/*margin: 10px;
padding: 10px;*/
/* margin: 10px;
padding: 10px; */
}
/*.two {
/* .two {
height: 42px;
display: none;
}
.three {
width: 42px;
*/ }`;
*/ }`;
return withRandomFileEditor(contents, 'css', (editor, doc) => {
editor.selections = [
new Selection(2, 7, 3, 10), // 2 properties partially under a single selection
@ -549,14 +549,14 @@ suite('Tests for Toggle Comment action from Emmet in nested css (SCSS)', () => {
test('toggle comment with multiple cursors selecting nested nodes (SCSS)', () => {
const expectedContents = `
.one {
/*height: 42px;*/
/* height: 42px; */
/*.two {
/* .two {
width: 42px;
}*/
} */
.three {
/*padding: 10px;*/
/* padding: 10px; */
}
}`;
return withRandomFileEditor(contents, 'css', (editor, doc) => {
@ -578,7 +578,7 @@ suite('Tests for Toggle Comment action from Emmet in nested css (SCSS)', () => {
});
test('toggle comment with multiple cursors selecting several nested nodes (SCSS)', () => {
const expectedContents = `
/*.one {
/* .one {
height: 42px;
.two {
@ -588,7 +588,7 @@ suite('Tests for Toggle Comment action from Emmet in nested css (SCSS)', () => {
.three {
padding: 10px;
}
}*/`;
} */`;
return withRandomFileEditor(contents, 'css', (editor, doc) => {
editor.selections = [
new Selection(1, 3, 1, 3), // cursor in the outside rule. And several cursors inside:
@ -611,14 +611,14 @@ suite('Tests for Toggle Comment action from Emmet in nested css (SCSS)', () => {
test('toggle comment with multiple cursors, but no selection (SCSS)', () => {
const expectedContents = `
.one {
/*height: 42px;*/
/* height: 42px; */
/*.two {
/* .two {
width: 42px;
}*/
} */
.three {
/*padding: 10px;*/
/* padding: 10px; */
}
}`;
return withRandomFileEditor(contents, 'css', (editor, doc) => {
@ -641,14 +641,14 @@ suite('Tests for Toggle Comment action from Emmet in nested css (SCSS)', () => {
test('toggle comment with multiple cursors and whole node selected (CSS)', () => {
const expectedContents = `
.one {
/*height: 42px;*/
/* height: 42px; */
/*.two {
/* .two {
width: 42px;
}*/
} */
.three {
/*padding: 10px;*/
/* padding: 10px; */
}
}`;
return withRandomFileEditor(contents, 'css', (editor, doc) => {
@ -673,11 +673,11 @@ suite('Tests for Toggle Comment action from Emmet in nested css (SCSS)', () => {
test('toggle comment when multiple nodes are completely under single selection (CSS)', () => {
const expectedContents = `
.one {
/*height: 42px;
/* height: 42px;
.two {
width: 42px;
}*/
} */
.three {
padding: 10px;
@ -701,11 +701,11 @@ suite('Tests for Toggle Comment action from Emmet in nested css (SCSS)', () => {
test('toggle comment when multiple nodes are partially under single selection (CSS)', () => {
const expectedContents = `
.one {
/*height: 42px;
/* height: 42px;
.two {
width: 42px;
*/ }
*/ }
.three {
padding: 10px;
@ -726,4 +726,29 @@ suite('Tests for Toggle Comment action from Emmet in nested css (SCSS)', () => {
});
});
});
test('toggle comment doesn\'t fail when start and end nodes differ HTML', () => {
const contents = `
<div>
<p>Hello</p>
</div>
`;
const expectedContents = `
<!-- <div>
<p>Hello</p>
</div> -->
`;
return withRandomFileEditor(contents, 'html', (editor, doc) => {
editor.selections = [
new Selection(1, 2, 2, 9), // <div> to <p> inclusive
];
return toggleComment().then(() => {
assert.equal(doc.getText(), expectedContents);
return toggleComment().then(() => {
assert.equal(doc.getText(), contents);
return Promise.resolve();
});
});
});
});
});

View File

@ -3,148 +3,147 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// import 'mocha';
// import * as assert from 'assert';
// import { Selection } from 'vscode';
// import { withRandomFileEditor, closeAllEditors } from './testUtils';
// import { updateImageSize } from '../updateImageSize';
import 'mocha';
import * as assert from 'assert';
import { Selection } from 'vscode';
import { withRandomFileEditor, closeAllEditors } from './testUtils';
import { updateImageSize } from '../updateImageSize';
// suite('Tests for Emmet actions on html tags', () => {
// teardown(closeAllEditors);
suite('Tests for Emmet actions on html tags', () => {
teardown(closeAllEditors);
// test('update image css with multiple cursors in css file', () => {
// const cssContents = `
// .one {
// margin: 10px;
// padding: 10px;
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// }
// .two {
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// height: 42px;
// }
// .three {
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// width: 42px;
// }
// `;
// const expectedContents = `
// .one {
// margin: 10px;
// padding: 10px;
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// width: 32px;
// height: 32px;
// }
// .two {
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// width: 32px;
// height: 32px;
// }
// .three {
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// height: 32px;
// width: 32px;
// }
// `;
// return withRandomFileEditor(cssContents, 'css', (editor, doc) => {
// editor.selections = [
// new Selection(4, 50, 4, 50),
// new Selection(7, 50, 7, 50),
// new Selection(11, 50, 11, 50)
// ];
test('update image css with multiple cursors in css file', () => {
const cssContents = `
.one {
margin: 10px;
padding: 10px;
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
}
.two {
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
height: 42px;
}
.three {
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
width: 42px;
}
`;
const expectedContents = `
.one {
margin: 10px;
padding: 10px;
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
width: 1024px;
height: 1024px;
}
.two {
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
width: 1024px;
height: 1024px;
}
.three {
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
height: 1024px;
width: 1024px;
}
`;
return withRandomFileEditor(cssContents, 'css', (editor, doc) => {
editor.selections = [
new Selection(4, 50, 4, 50),
new Selection(7, 50, 7, 50),
new Selection(11, 50, 11, 50)
];
// return updateImageSize()!.then(() => {
// assert.equal(doc.getText(), expectedContents);
// return Promise.resolve();
// });
// });
// });
return updateImageSize()!.then(() => {
assert.equal(doc.getText(), expectedContents);
return Promise.resolve();
});
});
});
// test('update image size in css in html file with multiple cursors', () => {
// const htmlWithCssContents = `
// <html>
// <style>
// .one {
// margin: 10px;
// padding: 10px;
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// }
// .two {
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// height: 42px;
// }
// .three {
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// width: 42px;
// }
// </style>
// </html>
// `;
// const expectedContents = `
// <html>
// <style>
// .one {
// margin: 10px;
// padding: 10px;
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// width: 32px;
// height: 32px;
// }
// .two {
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// width: 32px;
// height: 32px;
// }
// .three {
// background-image: url(https://github.com/microsoft/vscode/blob/master/resources/linux/code.png);
// height: 32px;
// width: 32px;
// }
// </style>
// </html>
// `;
// return withRandomFileEditor(htmlWithCssContents, 'html', (editor, doc) => {
// editor.selections = [
// new Selection(6, 50, 6, 50),
// new Selection(9, 50, 9, 50),
// new Selection(13, 50, 13, 50)
// ];
test('update image size in css in html file with multiple cursors', () => {
const htmlWithCssContents = `
<html>
<style>
.one {
margin: 10px;
padding: 10px;
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
}
.two {
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
height: 42px;
}
.three {
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
width: 42px;
}
</style>
</html>
`;
const expectedContents = `
<html>
<style>
.one {
margin: 10px;
padding: 10px;
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
width: 1024px;
height: 1024px;
}
.two {
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
width: 1024px;
height: 1024px;
}
.three {
background-image: url(https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png);
height: 1024px;
width: 1024px;
}
</style>
</html>
`;
return withRandomFileEditor(htmlWithCssContents, 'html', (editor, doc) => {
editor.selections = [
new Selection(6, 50, 6, 50),
new Selection(9, 50, 9, 50),
new Selection(13, 50, 13, 50)
];
// return updateImageSize()!.then(() => {
// assert.equal(doc.getText(), expectedContents);
// return Promise.resolve();
// });
// });
// });
return updateImageSize()!.then(() => {
assert.equal(doc.getText(), expectedContents);
return Promise.resolve();
});
});
});
// test('update image size in img tag in html file with multiple cursors', () => {
// const htmlwithimgtag = `
// <html>
// <img id="one" src="https://github.com/microsoft/vscode/blob/master/resources/linux/code.png" />
// <img id="two" src="https://github.com/microsoft/vscode/blob/master/resources/linux/code.png" width="56" />
// <img id="three" src="https://github.com/microsoft/vscode/blob/master/resources/linux/code.png" height="56" />
// </html>
// `;
// const expectedContents = `
// <html>
// <img id="one" src="https://github.com/microsoft/vscode/blob/master/resources/linux/code.png" width="32" height="32" />
// <img id="two" src="https://github.com/microsoft/vscode/blob/master/resources/linux/code.png" width="32" height="32" />
// <img id="three" src="https://github.com/microsoft/vscode/blob/master/resources/linux/code.png" height="32" width="32" />
// </html>
// `;
// return withRandomFileEditor(htmlwithimgtag, 'html', (editor, doc) => {
// editor.selections = [
// new Selection(2, 50, 2, 50),
// new Selection(3, 50, 3, 50),
// new Selection(4, 50, 4, 50)
// ];
test('update image size in img tag in html file with multiple cursors', () => {
const htmlwithimgtag = `
<html>
<img id="one" src="https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png" />
<img id="two" src="https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png" width="56" />
<img id="three" src="https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png" height="56" />
</html>
`;
const expectedContents = `
<html>
<img id="one" src="https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png" width="1024" height="1024" />
<img id="two" src="https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png" width="1024" height="1024" />
<img id="three" src="https://raw.githubusercontent.com/microsoft/vscode/master/resources/linux/code.png" height="1024" width="1024" />
</html>
`;
return withRandomFileEditor(htmlwithimgtag, 'html', (editor, doc) => {
editor.selections = [
new Selection(2, 50, 2, 50),
new Selection(3, 50, 3, 50),
new Selection(4, 50, 4, 50)
];
// return updateImageSize()!.then(() => {
// assert.equal(doc.getText(), expectedContents);
// return Promise.resolve();
// });
// });
// });
// });
return updateImageSize()!.then(() => {
assert.equal(doc.getText(), expectedContents);
return Promise.resolve();
});
});
});
});

View File

@ -9,13 +9,20 @@ import { Selection, workspace, ConfigurationTarget } from 'vscode';
import { withRandomFileEditor, closeAllEditors } from './testUtils';
import { wrapWithAbbreviation, wrapIndividualLinesWithAbbreviation } from '../abbreviationActions';
const htmlContentsForWrapTests = `
const htmlContentsForBlockWrapTests = `
<ul class="nav main">
<li class="item1">img</li>
<li class="item2">$hithere</li>
</ul>
`;
const htmlContentsForInlineWrapTests = `
<ul class="nav main">
<em class="item1">img</em>
<em class="item2">$hithere</em>
</ul>
`;
const wrapBlockElementExpected = `
<ul class="nav main">
<div>
@ -29,15 +36,19 @@ const wrapBlockElementExpected = `
const wrapInlineElementExpected = `
<ul class="nav main">
<span><li class="item1">img</li></span>
<span><li class="item2">$hithere</li></span>
<span><em class="item1">img</em></span>
<span><em class="item2">$hithere</em></span>
</ul>
`;
const wrapSnippetExpected = `
<ul class="nav main">
<a href=""><li class="item1">img</li></a>
<a href=""><li class="item2">$hithere</li></a>
<a href="">
<li class="item1">img</li>
</a>
<a href="">
<li class="item2">$hithere</li>
</a>
</ul>
`;
@ -56,10 +67,16 @@ const wrapMultiLineAbbrExpected = `
</ul>
`;
// technically a bug, but also a feature (requested behaviour)
// https://github.com/microsoft/vscode/issues/78015
const wrapInlineElementExpectedFormatFalse = `
<ul class="nav main">
<h1><li class="item1">img</li></h1>
<h1><li class="item2">$hithere</li></h1>
<h1>
<li class="item1">img</li>
</h1>
<h1>
<li class="item2">$hithere</li>
</h1>
</ul>
`;
@ -73,51 +90,51 @@ suite('Tests for Wrap with Abbreviations', () => {
const oldValueForSyntaxProfiles = workspace.getConfiguration('emmet').inspect('syntaxProfile');
test('Wrap with block element using multi cursor', () => {
return testWrapWithAbbreviation(multiCursors, 'div', wrapBlockElementExpected);
return testWrapWithAbbreviation(multiCursors, 'div', wrapBlockElementExpected, htmlContentsForBlockWrapTests);
});
test('Wrap with inline element using multi cursor', () => {
return testWrapWithAbbreviation(multiCursors, 'span', wrapInlineElementExpected);
return testWrapWithAbbreviation(multiCursors, 'span', wrapInlineElementExpected, htmlContentsForInlineWrapTests);
});
test('Wrap with snippet using multi cursor', () => {
return testWrapWithAbbreviation(multiCursors, 'a', wrapSnippetExpected);
return testWrapWithAbbreviation(multiCursors, 'a', wrapSnippetExpected, htmlContentsForBlockWrapTests);
});
test('Wrap with multi line abbreviation using multi cursor', () => {
return testWrapWithAbbreviation(multiCursors, 'ul>li', wrapMultiLineAbbrExpected);
return testWrapWithAbbreviation(multiCursors, 'ul>li', wrapMultiLineAbbrExpected, htmlContentsForBlockWrapTests);
});
test('Wrap with block element using multi cursor selection', () => {
return testWrapWithAbbreviation(multiCursorsWithSelection, 'div', wrapBlockElementExpected);
return testWrapWithAbbreviation(multiCursorsWithSelection, 'div', wrapBlockElementExpected, htmlContentsForBlockWrapTests);
});
test('Wrap with inline element using multi cursor selection', () => {
return testWrapWithAbbreviation(multiCursorsWithSelection, 'span', wrapInlineElementExpected);
return testWrapWithAbbreviation(multiCursorsWithSelection, 'span', wrapInlineElementExpected, htmlContentsForInlineWrapTests);
});
test('Wrap with snippet using multi cursor selection', () => {
return testWrapWithAbbreviation(multiCursorsWithSelection, 'a', wrapSnippetExpected);
return testWrapWithAbbreviation(multiCursorsWithSelection, 'a', wrapSnippetExpected, htmlContentsForBlockWrapTests);
});
test('Wrap with multi line abbreviation using multi cursor selection', () => {
return testWrapWithAbbreviation(multiCursorsWithSelection, 'ul>li', wrapMultiLineAbbrExpected);
return testWrapWithAbbreviation(multiCursorsWithSelection, 'ul>li', wrapMultiLineAbbrExpected, htmlContentsForBlockWrapTests);
});
test('Wrap with block element using multi cursor full line selection', () => {
return testWrapWithAbbreviation(multiCursorsWithFullLineSelection, 'div', wrapBlockElementExpected);
return testWrapWithAbbreviation(multiCursorsWithFullLineSelection, 'div', wrapBlockElementExpected, htmlContentsForBlockWrapTests);
});
test('Wrap with inline element using multi cursor full line selection', () => {
return testWrapWithAbbreviation(multiCursorsWithFullLineSelection, 'span', wrapInlineElementExpected);
return testWrapWithAbbreviation(multiCursorsWithFullLineSelection, 'span', wrapInlineElementExpected, htmlContentsForInlineWrapTests);
});
test('Wrap with snippet using multi cursor full line selection', () => {
return testWrapWithAbbreviation(multiCursorsWithFullLineSelection, 'a', wrapSnippetExpected);
return testWrapWithAbbreviation(multiCursorsWithFullLineSelection, 'a', wrapSnippetExpected, htmlContentsForBlockWrapTests);
});
test('Wrap with multi line abbreviation using multi cursor full line selection', () => {
return testWrapWithAbbreviation(multiCursorsWithFullLineSelection, 'ul>li', wrapMultiLineAbbrExpected);
return testWrapWithAbbreviation(multiCursorsWithFullLineSelection, 'ul>li', wrapMultiLineAbbrExpected, htmlContentsForBlockWrapTests);
});
test('Wrap with abbreviation and comment filter', () => {
@ -128,15 +145,31 @@ suite('Tests for Wrap with Abbreviations', () => {
`;
const expectedContents = `
<ul class="nav main">
<li class="hello">
line
</li>
<li class="hello">line</li>
<!-- /.hello -->
</ul>
`;
return testWrapWithAbbreviation([new Selection(2, 0, 2, 0)], 'li.hello|c', expectedContents, contents);
});
test('Wrap with abbreviation link', () => {
const contents = `
<ul class="nav main">
line
</ul>
`;
const expectedContents = `
<a href="https://example.com">
<div>
<ul class="nav main">
line
</ul>
</div>
</a>
`;
return testWrapWithAbbreviation([new Selection(1, 1, 1, 1)], 'a[href="https://example.com"]>div', expectedContents, contents);
});
test('Wrap with abbreviation entire node when cursor is on opening tag', () => {
const contents = `
<div class="nav main">
@ -192,8 +225,12 @@ suite('Tests for Wrap with Abbreviations', () => {
const wrapIndividualLinesExpected = `
<ul class="nav main">
<ul>
<li class="hello1"><li class="item1">This $10 is not a tabstop</li></li>
<li class="hello2"><li class="item2">hi.there</li></li>
<li class="hello1">
<li class="item1">This $10 is not a tabstop</li>
</li>
<li class="hello2">
<li class="item2">hi.there</li>
</li>
</ul>
</ul>
`;
@ -210,8 +247,12 @@ suite('Tests for Wrap with Abbreviations', () => {
const wrapIndividualLinesExpected = `
<ul class="nav main">
<ul>
<li class="hello1"><li class="item1">img</li></li>
<li class="hello2"><li class="item2">hi.there</li></li>
<li class="hello1">
<li class="item1">img</li>
</li>
<li class="hello2">
<li class="item2">hi.there</li>
</li>
</ul>
</ul>
`;
@ -228,9 +269,13 @@ suite('Tests for Wrap with Abbreviations', () => {
const wrapIndividualLinesExpected = `
<ul class="nav main">
<ul>
<li class="hello"><li class="item1">img</li></li>
<li class="hello">
<li class="item1">img</li>
</li>
<!-- /.hello -->
<li class="hello"><li class="item2">hi.there</li></li>
<li class="hello">
<li class="item2">hi.there</li>
</li>
<!-- /.hello -->
</ul>
</ul>
@ -257,9 +302,9 @@ suite('Tests for Wrap with Abbreviations', () => {
});
test('Wrap with abbreviation and format set to false', () => {
return workspace.getConfiguration('emmet').update('syntaxProfiles',{ 'html' : { 'format': false } } , ConfigurationTarget.Global).then(() => {
return testWrapWithAbbreviation(multiCursors,'h1',wrapInlineElementExpectedFormatFalse).then(() => {
return workspace.getConfiguration('emmet').update('syntaxProfiles',oldValueForSyntaxProfiles ? oldValueForSyntaxProfiles.globalValue : undefined, ConfigurationTarget.Global);
return workspace.getConfiguration('emmet').update('syntaxProfiles', { 'html' : { 'format': false } }, ConfigurationTarget.Global).then(() => {
return testWrapWithAbbreviation(multiCursors, 'h1', wrapInlineElementExpectedFormatFalse, htmlContentsForBlockWrapTests).then(() => {
return workspace.getConfiguration('emmet').update('syntaxProfiles', oldValueForSyntaxProfiles ? oldValueForSyntaxProfiles.globalValue : undefined, ConfigurationTarget.Global);
});
});
});
@ -302,28 +347,32 @@ suite('Tests for Wrap with Abbreviations', () => {
</ul>
`;
return testWrapWithAbbreviation([new Selection(2,2,3,33)], '.hello', wrapMultiLineJsxExpected, htmlContentsForWrapTests, 'jsx');
return testWrapWithAbbreviation([new Selection(2,2,3,33)], '.hello', wrapMultiLineJsxExpected, htmlContentsForBlockWrapTests, 'jsx');
});
test('Wrap individual line with abbreviation uses className for jsx files', () => {
const wrapIndividualLinesJsxExpected = `
<ul class="nav main">
<div className="hello1"><li class="item1">img</li></div>
<div className="hello2"><li class="item2">$hithere</li></div>
<div className="hello1">
<li class="item1">img</li>
</div>
<div className="hello2">
<li class="item2">$hithere</li>
</div>
</ul>
`;
return testWrapIndividualLinesWithAbbreviation([new Selection(2,2,3,33)], '.hello$*', wrapIndividualLinesJsxExpected, htmlContentsForWrapTests, 'jsx');
return testWrapIndividualLinesWithAbbreviation([new Selection(2,2,3,33)], '.hello$*', wrapIndividualLinesJsxExpected, htmlContentsForBlockWrapTests, 'jsx');
});
});
function testWrapWithAbbreviation(selections: Selection[], abbreviation: string, expectedContents: string, input: string = htmlContentsForWrapTests, fileExtension: string = 'html'): Thenable<any> {
function testWrapWithAbbreviation(selections: Selection[], abbreviation: string, expectedContents: string, input: string, fileExtension: string = 'html'): Thenable<any> {
return withRandomFileEditor(input, fileExtension, (editor, _) => {
editor.selections = selections;
const promise = wrapWithAbbreviation({ abbreviation });
if (!promise) {
assert.equal(1, 2, 'Wrap with Abbreviation returned undefined.');
assert.equal(1, 2, 'Wrap with Abbreviation returned undefined.');
return Promise.resolve();
}
@ -334,7 +383,7 @@ function testWrapWithAbbreviation(selections: Selection[], abbreviation: string,
});
}
function testWrapIndividualLinesWithAbbreviation(selections: Selection[], abbreviation: string, expectedContents: string, input: string = htmlContentsForWrapTests, fileExtension: string = 'html'): Thenable<any> {
function testWrapIndividualLinesWithAbbreviation(selections: Selection[], abbreviation: string, expectedContents: string, input: string, fileExtension: string = 'html'): Thenable<any> {
return withRandomFileEditor(input, fileExtension, (editor, _) => {
editor.selections = selections;
const promise = wrapIndividualLinesWithAbbreviation({ abbreviation });