From 62899d10cddc58aea83e32a695141ca1dde66dd4 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Fri, 8 Sep 2017 16:45:47 -0700 Subject: [PATCH] Add simple baseline tests for insertion positions --- src/harness/unittests/extractMethods.ts | 58 ++++++++++++++++++- .../extractMethod/extractMethod23.ts | 43 ++++++++++++++ .../extractMethod/extractMethod24.ts | 43 ++++++++++++++ .../extractMethod/extractMethod25.ts | 26 +++++++++ .../extractMethod/extractMethod26.ts | 31 ++++++++++ .../extractMethod/extractMethod27.ts | 34 +++++++++++ .../extractMethod/extractMethod28.ts | 34 +++++++++++ 7 files changed, 267 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/extractMethod/extractMethod23.ts create mode 100644 tests/baselines/reference/extractMethod/extractMethod24.ts create mode 100644 tests/baselines/reference/extractMethod/extractMethod25.ts create mode 100644 tests/baselines/reference/extractMethod/extractMethod26.ts create mode 100644 tests/baselines/reference/extractMethod/extractMethod27.ts create mode 100644 tests/baselines/reference/extractMethod/extractMethod28.ts diff --git a/src/harness/unittests/extractMethods.ts b/src/harness/unittests/extractMethods.ts index 75404d12bf0..edcc80cd57c 100644 --- a/src/harness/unittests/extractMethods.ts +++ b/src/harness/unittests/extractMethods.ts @@ -224,7 +224,7 @@ namespace ts { testExtractRange(` function f() { while (true) { - [#| + [#| if (x) { return; } |] @@ -234,7 +234,7 @@ namespace ts { testExtractRange(` function f() { while (true) { - [#| + [#| [$|if (x) { } return;|] @@ -655,6 +655,60 @@ function test(x: number) { finally { [#|return 1;|] } +}`); + // Extraction position - namespace + testExtractMethod("extractMethod23", + `namespace NS { + function M1() { } + function M2() { + [#|return 1;|] + } + function M3() { } +}`); + // Extraction position - function + testExtractMethod("extractMethod24", + `function Outer() { + function M1() { } + function M2() { + [#|return 1;|] + } + function M3() { } +}`); + // Extraction position - file + testExtractMethod("extractMethod25", + `function M1() { } +function M2() { + [#|return 1;|] +} +function M3() { }`); + // Extraction position - class without ctor + testExtractMethod("extractMethod26", + `class C { + M1() { } + M2() { + [#|return 1;|] + } + M3() { } +}`); + // Extraction position - class with ctor in middle + testExtractMethod("extractMethod27", + `class C { + M1() { } + M2() { + [#|return 1;|] + } + constructor() { } + M3() { } +}`); + // Extraction position - class with ctor at end + testExtractMethod("extractMethod28", + `class C { + M1() { } + M2() { + [#|return 1;|] + } + M3() { } + constructor() { } }`); }); diff --git a/tests/baselines/reference/extractMethod/extractMethod23.ts b/tests/baselines/reference/extractMethod/extractMethod23.ts new file mode 100644 index 00000000000..8bc3db86cc1 --- /dev/null +++ b/tests/baselines/reference/extractMethod/extractMethod23.ts @@ -0,0 +1,43 @@ +// ==ORIGINAL== +namespace NS { + function M1() { } + function M2() { + return 1; + } + function M3() { } +} +// ==SCOPE::function 'M2'== +namespace NS { + function M1() { } + function M2() { + return newFunction(); + + function newFunction() { + return 1; + } + } + function M3() { } +} +// ==SCOPE::namespace 'NS'== +namespace NS { + function M1() { } + function M2() { + return newFunction(); + } + function newFunction() { + return 1; + } + + function M3() { } +} +// ==SCOPE::global scope== +namespace NS { + function M1() { } + function M2() { + return newFunction(); + } + function M3() { } +} +function newFunction() { + return 1; +} diff --git a/tests/baselines/reference/extractMethod/extractMethod24.ts b/tests/baselines/reference/extractMethod/extractMethod24.ts new file mode 100644 index 00000000000..ec6d6cd3f12 --- /dev/null +++ b/tests/baselines/reference/extractMethod/extractMethod24.ts @@ -0,0 +1,43 @@ +// ==ORIGINAL== +function Outer() { + function M1() { } + function M2() { + return 1; + } + function M3() { } +} +// ==SCOPE::function 'M2'== +function Outer() { + function M1() { } + function M2() { + return newFunction(); + + function newFunction() { + return 1; + } + } + function M3() { } +} +// ==SCOPE::function 'Outer'== +function Outer() { + function M1() { } + function M2() { + return newFunction(); + } + function newFunction() { + return 1; + } + + function M3() { } +} +// ==SCOPE::global scope== +function Outer() { + function M1() { } + function M2() { + return newFunction(); + } + function M3() { } +} +function newFunction() { + return 1; +} diff --git a/tests/baselines/reference/extractMethod/extractMethod25.ts b/tests/baselines/reference/extractMethod/extractMethod25.ts new file mode 100644 index 00000000000..a7a971315a1 --- /dev/null +++ b/tests/baselines/reference/extractMethod/extractMethod25.ts @@ -0,0 +1,26 @@ +// ==ORIGINAL== +function M1() { } +function M2() { + return 1; +} +function M3() { } +// ==SCOPE::function 'M2'== +function M1() { } +function M2() { + return newFunction(); + + function newFunction() { + return 1; + } +} +function M3() { } +// ==SCOPE::global scope== +function M1() { } +function M2() { + return newFunction(); +} +function newFunction() { + return 1; +} + +function M3() { } \ No newline at end of file diff --git a/tests/baselines/reference/extractMethod/extractMethod26.ts b/tests/baselines/reference/extractMethod/extractMethod26.ts new file mode 100644 index 00000000000..d0619ea9b0a --- /dev/null +++ b/tests/baselines/reference/extractMethod/extractMethod26.ts @@ -0,0 +1,31 @@ +// ==ORIGINAL== +class C { + M1() { } + M2() { + return 1; + } + M3() { } +} +// ==SCOPE::class 'C'== +class C { + M1() { } + M2() { + return this.newFunction(); + } + private newFunction() { + return 1; + } + + M3() { } +} +// ==SCOPE::global scope== +class C { + M1() { } + M2() { + return newFunction(); + } + M3() { } +} +function newFunction() { + return 1; +} diff --git a/tests/baselines/reference/extractMethod/extractMethod27.ts b/tests/baselines/reference/extractMethod/extractMethod27.ts new file mode 100644 index 00000000000..9f1f1e84a77 --- /dev/null +++ b/tests/baselines/reference/extractMethod/extractMethod27.ts @@ -0,0 +1,34 @@ +// ==ORIGINAL== +class C { + M1() { } + M2() { + return 1; + } + constructor() { } + M3() { } +} +// ==SCOPE::class 'C'== +class C { + M1() { } + M2() { + return this.newFunction(); + } + constructor() { } + private newFunction() { + return 1; + } + + M3() { } +} +// ==SCOPE::global scope== +class C { + M1() { } + M2() { + return newFunction(); + } + constructor() { } + M3() { } +} +function newFunction() { + return 1; +} diff --git a/tests/baselines/reference/extractMethod/extractMethod28.ts b/tests/baselines/reference/extractMethod/extractMethod28.ts new file mode 100644 index 00000000000..9b97e581548 --- /dev/null +++ b/tests/baselines/reference/extractMethod/extractMethod28.ts @@ -0,0 +1,34 @@ +// ==ORIGINAL== +class C { + M1() { } + M2() { + return 1; + } + M3() { } + constructor() { } +} +// ==SCOPE::class 'C'== +class C { + M1() { } + M2() { + return this.newFunction(); + } + private newFunction() { + return 1; + } + + M3() { } + constructor() { } +} +// ==SCOPE::global scope== +class C { + M1() { } + M2() { + return newFunction(); + } + M3() { } + constructor() { } +} +function newFunction() { + return 1; +}