add tests for ToAnon, ToArrow and available arrow

This commit is contained in:
BigAru 2018-10-18 11:52:00 +02:00
parent e697856a7d
commit cc07d68210
15 changed files with 257 additions and 0 deletions

View file

@ -0,0 +1,33 @@
/// <reference path='fourslash.ts' />
//// /*z*/c/*y*/onst /*x*/f/*w*/oo = /*v*/(/*u*//*t*/a/*s*/, b) /*r*/=/*q*/> /*p*/4/*o*/2;
goTo.select("z", "y");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to anonymous function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to arrow function");
goTo.select("x", "w");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to anonymous function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to arrow function");
goTo.select("v", "u");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to anonymous function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to arrow function");
goTo.select("t", "s");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to anonymous function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to arrow function");
goTo.select("r", "q");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to anonymous function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to arrow function");
goTo.select("p", "o");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to anonymous function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to arrow function");

View file

@ -0,0 +1,23 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/a/*y*/ => {
//// // secret word
//// return a + 1;
//// /*
//// hidden msg
//// */
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to anonymous function",
actionDescription: "Convert to anonymous function",
newContent: `const foo = function(a) {
// secret word
return a + 1;
/*
hidden msg
*/
};`,
});

View file

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/a/*y*/ => {
//// let b = 1;
//// return a + b;
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to anonymous function",
actionDescription: "Convert to anonymous function",
newContent: `const foo = function(a) {
let b = 1;
return a + b;
};`,
});

View file

@ -0,0 +1,13 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/(/*y*/a,b,c) => a + 1;
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to anonymous function",
actionDescription: "Convert to anonymous function",
newContent: `const foo = function(a, b, c) {
return a + 1;
};`,
});

View file

@ -0,0 +1,13 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/(/*y*/) => 1 + 1;
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to anonymous function",
actionDescription: "Convert to anonymous function",
newContent: `const foo = function() {
return 1 + 1;
};`,
});

View file

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/f/*y*/unction() {
//// let a = 41;
//// return a + 1;
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to arrow function",
actionDescription: "Convert to arrow function",
newContent: `const foo = () => {
let a = 41;
return a + 1;
};`,
});

View file

@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/f/*y*/unction() {
//// // secret
//// let a = 41;
//// /*
//// msg
//// */
//// return a + 1;
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to arrow function",
actionDescription: "Convert to arrow function",
newContent: `const foo = () => {
// secret
let a = 41;
/*
msg
*/
return a + 1;
};`,
});

View file

@ -0,0 +1,13 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/f/*y*/unction(a, b, c) {
//// return a + b + c;
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to arrow function",
actionDescription: "Convert to arrow function",
newContent: `const foo = (a, b, c) => a + b + c;`,
});

View file

@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
//// let bar;
//// const foo = /*x*/f/*y*/unction() {
//// bar = 42;
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to arrow function",
actionDescription: "Convert to arrow function",
newContent: `let bar;
const foo = () => bar = 42;`,
});

View file

@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/f/*y*/unction() {
//// let bar;
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to arrow function",
actionDescription: "Convert to arrow function",
newContent: `const foo = () => {
let bar;
};`,
});

View file

@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
//// function s(){}
//// const foo = /*x*/f/*y*/unction() {
//// s();
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to arrow function",
actionDescription: "Convert to arrow function",
newContent: `function s(){}
const foo = () => s();`,
});

View file

@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/f/*y*/unction() {
//// for (let i = 0; i < 5; i++) { }
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to arrow function",
actionDescription: "Convert to arrow function",
newContent: `const foo = () => {
for (let i = 0; i < 5; i++) { }
};`,
});

View file

@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/f/*y*/unction() {
//// if (true) { }
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to arrow function",
actionDescription: "Convert to arrow function",
newContent: `const foo = () => {
if (true) { }
};`,
});

View file

@ -0,0 +1,13 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/f/*y*/unction() {
//// return 42;
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to arrow function",
actionDescription: "Convert to arrow function",
newContent: `const foo = () => 42;`,
});

View file

@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
//// const foo = /*x*/f/*y*/unction() {
//// while (true) { }
//// };
goTo.select("x", "y");
edit.applyRefactor({
refactorName: "Convert arrow function or function expression",
actionName: "Convert to arrow function",
actionDescription: "Convert to arrow function",
newContent: `const foo = () => {
while (true) { }
};`,
});