Add tests for convert to named parameters refactor

This commit is contained in:
Gabriela Britto 2019-01-28 15:53:39 -08:00
parent 3243b4b4f2
commit b668e342c4
18 changed files with 280 additions and 1 deletions

View File

@ -3,6 +3,7 @@
////function f(/*a*/a: number, b: string/*b*/): string {
//// return b;
////}
////f(4, "b");
goTo.select("a", "b");
edit.applyRefactor({
@ -11,5 +12,6 @@ edit.applyRefactor({
actionDescription: "Convert to named parameters",
newContent: `function f({ a, b }: { a: number; b: string; }): string {
return b;
}`
}
f({ a: 4, b: "b" });`
});

View File

@ -0,0 +1,23 @@
/// <reference path='fourslash.ts' />
////class Foo {
//// /*a*/bar/*b*/(t: string, s: string): string {
//// return s + t;
//// }
////}
////var foo = new Foo();
////foo.bar("a", "b");
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `class Foo {
bar({ t, s }: { t: string; s: string; }): string {
return s + t;
}
}
var foo = new Foo();
foo.bar({ t: "a", s: "b" });`
});

View File

@ -0,0 +1,7 @@
/// <reference path='fourslash.ts' />
////const { foo, bar } = { foo: /*a*/(a: number, b: number)/*b*/ => {}, bar: () => {} };
////foo(1, 2);
goTo.select("a", "b");
verify.not.refactorAvailable("Convert to named parameters");

View File

@ -0,0 +1,13 @@
/// <reference path='fourslash.ts' />
////const foo = /*a*/function/*b*/(a: number, b: number) {};
////foo(1, 2);
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `const foo = function({ a, b }: { a: number; b: number; }) {};
foo({ a: 1, b: 2 });`
});

View File

@ -0,0 +1,13 @@
/// <reference path='fourslash.ts' />
////const foo = /*a*/(a: number, b: number)/*b*/ => {};
////foo(1, 2);
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `const foo = ({ a, b }: { a: number; b: number; }) => {};
foo({ a: 1, b: 2 });`
});

View File

@ -0,0 +1,7 @@
/// <reference path='fourslash.ts' />
////var foo = /*a*/(a: number, b: number)/*b*/ => {};
////foo(1, 2);
goTo.select("a", "b");
verify.not.refactorAvailable("Convert to named parameters");

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
////const c = class {
//// constructor(/*a*/a: number, b = { x: 1 }/*b*/) {}
////}
////var x = new c(2);
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `const c = class {
constructor({ a, b = { x: 1 } }: { a: number; b?: { x: number; }; }) {}
}
var x = new c({ a: 2 });`
});

View File

@ -0,0 +1,8 @@
/// <reference path='fourslash.ts' />
/////export default class {
//// constructor(/*a*/a: number, b = { x: 1 }/*b*/) {}
////}
goTo.select("a", "b");
verify.not.refactorAvailable("Convert to named parameters");

View File

@ -0,0 +1,23 @@
/// <reference path='fourslash.ts' />
////class Foo<T> {
//// /*a*/bar/*b*/(t: T, s: T) {
//// return s;
//// }
////}
////var foo = new Foo();
////foo.bar("a", "b");
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `class Foo<T> {
bar({ t, s }: { t: T; s: T; }) {
return s;
}
}
var foo = new Foo();
foo.bar({ t: "a", s: "b" });`
});

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
////function foo<T, S>(/*a*/t: T, s: S/*b*/) {
//// return s;
////}
////foo("a", "b");
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `function foo<T, S>({ t, s }: { t: T; s: S; }) {
return s;
}
foo({ t: "a", s: "b" });`
});

View File

@ -0,0 +1,27 @@
/// <reference path='fourslash.ts' />
////class Foo {
//// t: string;
//// s: string;
//// /*a*/constructor/*b*/(t: string, s: string) {
//// this.t = t;
//// this.s = s;
//// }
////}
////var foo = new Foo("a", "b");
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `class Foo {
t: string;
s: string;
constructor({ t, s }: { t: string; s: string; }) {
this.t = t;
this.s = s;
}
}
var foo = new Foo({ t: "a", s: "b" });`
});

View File

@ -0,0 +1,21 @@
/// <reference path='fourslash.ts' />
////class Foo {
//// static /*a*/bar/*b*/(t: string, s: string): string {
//// return s + t;
//// }
////}
////Foo.bar("a", "b");
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `class Foo {
static bar({ t, s }: { t: string; s: string; }): string {
return s + t;
}
}
Foo.bar({ t: "a", s: "b" });`
});

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
////function f(/*a*/a: number, b = { x: 1, z: { s: true } }/*b*/) {
//// return b;
////}
////f(2);
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `function f({ a, b = { x: 1, z: { s: true } } }: { a: number; b?: { x: number; z: { s: boolean; }; }; }) {
return b;
}
f({ a: 2 });`
});

View File

@ -0,0 +1,23 @@
/// <reference path='fourslash.ts' />
////class Foo {
//// /*a*/bar/*b*/(t: string, s: string): string {
//// return s + t;
//// }
////}
////var foo = new Foo();
////foo['bar']("a", "b");
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `class Foo {
bar({ t, s }: { t: string; s: string; }): string {
return s + t;
}
}
var foo = new Foo();
foo['bar']({ t: "a", s: "b" });`
});

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
////function f(/*a*/a: number, b: string = "1"/*b*/): string {
//// return b;
////}
////f(4, "b");
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `function f({ a, b = "1" }: { a: number; b?: string; }): string {
return b;
}
f({ a: 4, b: "b" });`
});

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
////function f(/*a*/a?: number, b: string = "1"/*b*/): string {
//// return b;
////}
////f();
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `function f({ a, b = "1" }: { a?: number; b?: string; } = {}): string {
return b;
}
f();`
});

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
////function f(/*a*/a: number, b = 1/*b*/) {
//// return b;
////}
////f(2);
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Convert to named parameters",
actionName: "Convert to named parameters",
actionDescription: "Convert to named parameters",
newContent: `function f({ a, b = 1 }: { a: number; b?: number; }) {
return b;
}
f({ a: 2 });`
});

View File

@ -0,0 +1,10 @@
/// <reference path='fourslash.ts' />
////function f(a: number, b: number);
////function f(/*a*/a: number, b = 1/*b*/) {
//// return b;
////}
////f(2);
goTo.select("a", "b");
verify.not.refactorAvailable("Convert to named parameters");