mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 01:34:55 -06:00
Add tests for convert to named parameters refactor
This commit is contained in:
parent
3243b4b4f2
commit
b668e342c4
@ -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" });`
|
||||
});
|
||||
23
tests/cases/fourslash/refactorConvertToNamedParameters1.ts
Normal file
23
tests/cases/fourslash/refactorConvertToNamedParameters1.ts
Normal 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" });`
|
||||
});
|
||||
@ -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");
|
||||
13
tests/cases/fourslash/refactorConvertToNamedParameters11.ts
Normal file
13
tests/cases/fourslash/refactorConvertToNamedParameters11.ts
Normal 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 });`
|
||||
});
|
||||
13
tests/cases/fourslash/refactorConvertToNamedParameters12.ts
Normal file
13
tests/cases/fourslash/refactorConvertToNamedParameters12.ts
Normal 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 });`
|
||||
});
|
||||
@ -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");
|
||||
17
tests/cases/fourslash/refactorConvertToNamedParameters14.ts
Normal file
17
tests/cases/fourslash/refactorConvertToNamedParameters14.ts
Normal 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 });`
|
||||
});
|
||||
@ -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");
|
||||
23
tests/cases/fourslash/refactorConvertToNamedParameters16.ts
Normal file
23
tests/cases/fourslash/refactorConvertToNamedParameters16.ts
Normal 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" });`
|
||||
});
|
||||
17
tests/cases/fourslash/refactorConvertToNamedParameters17.ts
Normal file
17
tests/cases/fourslash/refactorConvertToNamedParameters17.ts
Normal 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" });`
|
||||
});
|
||||
27
tests/cases/fourslash/refactorConvertToNamedParameters2.ts
Normal file
27
tests/cases/fourslash/refactorConvertToNamedParameters2.ts
Normal 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" });`
|
||||
});
|
||||
21
tests/cases/fourslash/refactorConvertToNamedParameters3.ts
Normal file
21
tests/cases/fourslash/refactorConvertToNamedParameters3.ts
Normal 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" });`
|
||||
});
|
||||
17
tests/cases/fourslash/refactorConvertToNamedParameters4.ts
Normal file
17
tests/cases/fourslash/refactorConvertToNamedParameters4.ts
Normal 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 });`
|
||||
});
|
||||
23
tests/cases/fourslash/refactorConvertToNamedParameters5.ts
Normal file
23
tests/cases/fourslash/refactorConvertToNamedParameters5.ts
Normal 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" });`
|
||||
});
|
||||
17
tests/cases/fourslash/refactorConvertToNamedParameters6.ts
Normal file
17
tests/cases/fourslash/refactorConvertToNamedParameters6.ts
Normal 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" });`
|
||||
});
|
||||
17
tests/cases/fourslash/refactorConvertToNamedParameters7.ts
Normal file
17
tests/cases/fourslash/refactorConvertToNamedParameters7.ts
Normal 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();`
|
||||
});
|
||||
17
tests/cases/fourslash/refactorConvertToNamedParameters8.ts
Normal file
17
tests/cases/fourslash/refactorConvertToNamedParameters8.ts
Normal 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 });`
|
||||
});
|
||||
10
tests/cases/fourslash/refactorConvertToNamedParameters9.ts
Normal file
10
tests/cases/fourslash/refactorConvertToNamedParameters9.ts
Normal 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");
|
||||
Loading…
x
Reference in New Issue
Block a user