From b285ef165bfe6f16994e610bb2dbde6ca0180c60 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 17 Sep 2014 17:40:32 -0700 Subject: [PATCH] Added fourslash tests. --- .../scriptLexicalStructureFunctions.ts | 23 ++++++++++ .../scriptLexicalStructureFunctionsBroken.ts | 12 +++++ .../scriptLexicalStructureFunctionsBroken2.ts | 13 ++++++ .../fourslash/scriptLexicalStructureItems.ts | 1 + ...iptLexicalStructureItemsExternalModules.ts | 4 +- .../scriptLexicalStructureModules.ts | 44 +++++++++++++++++++ 6 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/scriptLexicalStructureFunctions.ts create mode 100644 tests/cases/fourslash/scriptLexicalStructureFunctionsBroken.ts create mode 100644 tests/cases/fourslash/scriptLexicalStructureFunctionsBroken2.ts create mode 100644 tests/cases/fourslash/scriptLexicalStructureModules.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureFunctions.ts b/tests/cases/fourslash/scriptLexicalStructureFunctions.ts new file mode 100644 index 00000000000..7723bd0ee68 --- /dev/null +++ b/tests/cases/fourslash/scriptLexicalStructureFunctions.ts @@ -0,0 +1,23 @@ +/// + +////{| "itemName": "", "kind": "module" |} +//// +////{| "itemName": "foo", "kind": "function" |}function foo() { +//// var x = 10; +//// {| "itemName": "bar", "kind": "function", "parentName": "foo" |}function bar() { +//// var y = 10; +//// {| "itemName": "biz", "kind": "function", "parentName": "bar" |}function biz() { +//// var z = 10; +//// } +//// } +////} +//// +////{| "itemName": "baz", "kind": "function" |}function baz() { +//// var v = 10; +////} + +test.markers().forEach((marker) => { + verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +}); + +verify.getScriptLexicalStructureListCount(5); // 4 functions + global diff --git a/tests/cases/fourslash/scriptLexicalStructureFunctionsBroken.ts b/tests/cases/fourslash/scriptLexicalStructureFunctionsBroken.ts new file mode 100644 index 00000000000..687b9b87296 --- /dev/null +++ b/tests/cases/fourslash/scriptLexicalStructureFunctionsBroken.ts @@ -0,0 +1,12 @@ +/// + +////{| "itemName": "f", "kind": "function" |} +////function f() { +//// function; +////} + +test.markers().forEach((marker) => { + verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +}); + +verify.getScriptLexicalStructureListCount(1); // 1 function - no global since the inner function thinks it has a declaration. diff --git a/tests/cases/fourslash/scriptLexicalStructureFunctionsBroken2.ts b/tests/cases/fourslash/scriptLexicalStructureFunctionsBroken2.ts new file mode 100644 index 00000000000..1ac7ed09ad8 --- /dev/null +++ b/tests/cases/fourslash/scriptLexicalStructureFunctionsBroken2.ts @@ -0,0 +1,13 @@ +/// + +////function; +////{| "itemName": "f", "kind": "function" |} +////function f() { +//// function; +////} + +test.markers().forEach((marker) => { + verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +}); + +verify.getScriptLexicalStructureListCount(1); // 1 function with no global - the broken declaration adds nothing for us at the global scope. diff --git a/tests/cases/fourslash/scriptLexicalStructureItems.ts b/tests/cases/fourslash/scriptLexicalStructureItems.ts index 025fd223fb9..e18f49c1db9 100644 --- a/tests/cases/fourslash/scriptLexicalStructureItems.ts +++ b/tests/cases/fourslash/scriptLexicalStructureItems.ts @@ -49,3 +49,4 @@ test.markers().forEach((marker) => { } }); +verify.getScriptLexicalStructureListCount(23); diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules.ts b/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules.ts index dd8f64d87a2..550f1aed783 100644 --- a/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules.ts +++ b/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules.ts @@ -4,8 +4,8 @@ //// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; ////} -verify.getScriptLexicalStructureListCount(2); // external module node + class + property - test.markers().forEach((marker) => { verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); + +verify.getScriptLexicalStructureListCount(2); // external module node + class + property diff --git a/tests/cases/fourslash/scriptLexicalStructureModules.ts b/tests/cases/fourslash/scriptLexicalStructureModules.ts new file mode 100644 index 00000000000..c7446111a0a --- /dev/null +++ b/tests/cases/fourslash/scriptLexicalStructureModules.ts @@ -0,0 +1,44 @@ + +////{| "itemName": "\"X.Y.Z\"", "kind": "module" |} +////declare module "X.Y.Z" { +////} +//// +////{| "itemName": "A.B.C", "kind": "module" |} +////module A.B.C { +//// {| "itemName": "x", "kind": "var", "parent": "A.B.C" |} +//// export var x; +////} +//// +////{| "itemName": "A.B", "kind": "module" |} +////module A.B { +//// {| "itemName": "y", "kind": "var", "parent": "A.B" |} +//// export var y; +////} +//// +////{| "itemName": "A", "kind": "module" |} +////module A { +//// {| "itemName": "z", "kind": "var", "parent": "A" |} +//// export var z; +////} +//// +////{| "itemName": "A", "kind": "module" |} +////module A { +//// {| "itemName": "B", "kind": "module", "parent": "E" |} +//// module B { +//// {| "itemName": "C", "kind": "module", "parent": "F" |} +//// module C { +//// {| "itemName": "x", "kind": "var", "parent": "C" |} +//// declare var x; +//// } +//// } +////} + + +test.markers().forEach((marker) => { + verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +}); + +/// We have 7 module keywords, and 4 var keywords. +/// The declarations of A.B.C.x do not get merged, so the 4 vars are independent. +/// The two 'A' modules, however, do get merged, so in reality we have 6 modules. +verify.getScriptLexicalStructureListCount(10);