Skip to content

Commit 424f2c9

Browse files
committed
More tests
1 parent 34624a0 commit 424f2c9

9 files changed

+34
-29
lines changed

src/harness/fourslash.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,8 +2709,8 @@ Actual: ${stringify(fullActual)}`);
27092709
return this.languageService.getDocumentHighlights(this.activeFile.fileName, this.currentCaretPosition, filesToSearch);
27102710
}
27112711

2712-
public verifyRangesAreOccurrences(isWriteAccess?: boolean) {
2713-
const ranges = this.getRanges();
2712+
public verifyRangesAreOccurrences(isWriteAccess?: boolean, ranges?: Range[]) {
2713+
ranges = ranges || this.getRanges();
27142714
for (const r of ranges) {
27152715
this.goToRangeStart(r);
27162716
this.verifyOccurrencesAtPositionListCount(ranges.length);
@@ -4084,8 +4084,8 @@ namespace FourSlashInterface {
40844084
this.state.verifyOccurrencesAtPositionListCount(expectedCount);
40854085
}
40864086

4087-
public rangesAreOccurrences(isWriteAccess?: boolean) {
4088-
this.state.verifyRangesAreOccurrences(isWriteAccess);
4087+
public rangesAreOccurrences(isWriteAccess?: boolean, ranges?: FourSlash.Range[]) {
4088+
this.state.verifyRangesAreOccurrences(isWriteAccess, ranges);
40894089
}
40904090

40914091
public rangesWithSameTextAreRenameLocations() {

tests/cases/fourslash/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ declare namespace FourSlashInterface {
228228
*/
229229
referenceGroups(starts: ArrayOrSingle<string> | ArrayOrSingle<Range>, parts: ReadonlyArray<ReferenceGroup>): void;
230230
singleReferenceGroup(definition: ReferencesDefinition, ranges?: Range[]): void;
231-
rangesAreOccurrences(isWriteAccess?: boolean): void;
231+
rangesAreOccurrences(isWriteAccess?: boolean, ranges?: Range[]): void;
232232
rangesWithSameTextAreRenameLocations(): void;
233233
rangesAreRenameLocations(options?: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges?: Range[] });
234234
findReferencesDefinitionDisplayPartsAtCaretAre(expected: ts.SymbolDisplayPart[]): void;

tests/cases/fourslash/javaScriptClass2.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
// @Filename: Foo.js
77
//// class Foo {
88
//// constructor() {
9-
//// this.[|union|] = 'foo';
10-
//// this.[|union|] = 100;
9+
//// [|this.[|{| "declarationRangeIndex": 0 |}union|] = 'foo';|]
10+
//// [|this.[|{| "declarationRangeIndex": 2 |}union|] = 100;|]
1111
//// }
1212
//// method() { return this.[|union|]; }
1313
//// }
1414
//// var x = new Foo();
1515
//// x.[|union|];
1616

17-
verify.rangesAreRenameLocations();
17+
verify.rangesAreRenameLocations(test.rangesByText().get("union"));

tests/cases/fourslash/jsDocServices.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
/////**
88
//// * @param /*use*/[|foo|] I pity the foo
99
//// */
10-
////function f([|/*def*/{| "isWriteAccess": true, "isDefinition": true |}foo|]: I) {
10+
////function f([|[|/*def*/{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 1 |}foo|]: I|]) {
1111
//// return [|foo|];
1212
////}
1313

14-
const ranges = test.ranges();
14+
const [r0, r1Def, r1, r2] = test.ranges();
15+
const ranges = [r0, r1, r2];
1516
goTo.marker("use");
1617
verify.goToDefinitionIs("def");
1718
verify.goToType("use", "I");
1819

1920
goTo.marker("use");
2021
verify.quickInfoIs("(parameter) foo: I", "I pity the foo");
2122

22-
verify.singleReferenceGroup("(parameter) foo: I");
23-
verify.rangesAreDocumentHighlights();
24-
verify.rangesAreRenameLocations();
23+
verify.singleReferenceGroup("(parameter) foo: I", ranges);
24+
verify.rangesAreDocumentHighlights(ranges);
25+
verify.rangesAreRenameLocations(ranges);

tests/cases/fourslash/jsdocTypedefTagSemanticMeaning0.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
// @allowJs: true
44
// @Filename: a.js
55

6-
/////** @typedef {number} [|{| "isWriteAccess": true, "isDefinition": true |}T|] */
6+
/////** [|@typedef {number} [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|]|] */
77

8-
////const [|{| "isWriteAccess": true, "isDefinition": true |}T|] = 1;
8+
////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}T|] = 1;|]
99

1010
/////** @type {[|T|]} */
1111
////const n = [|T|];
1212

13-
const [t0, v0, t1, v1] = test.ranges();
13+
const [t0Def, t0, v0Def, v0, t1, v1] = test.ranges();
1414

1515
verify.singleReferenceGroup("type T = number", [t0, t1]);
1616
verify.singleReferenceGroup("const T: 1", [v0, v1]);

tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// @Filename: a.js
55

66
/////** @typedef {number} */
7-
////const [|{| "isWriteAccess": true, "isDefinition": true |}T|] = 1;
7+
////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|] = 1;|]
88

99
/////** @type {[|T|]} */
1010
////const n = [|T|];
1111

12-
verify.singleReferenceGroup("type T = number\nconst T: 1");
12+
verify.singleReferenceGroup("type T = number\nconst T: 1", test.rangesByText().get("T"));

tests/cases/fourslash/jsdocTypedefTagServices.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
/////**
77
//// * Doc comment
8-
//// * @typedef /*def*/[|{| "isWriteAccess": true, "isDefinition": true |}Product|]
8+
//// * [|@typedef /*def*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Product|]
99
//// * @property {string} title
10-
//// */
10+
//// |]*/
1111

1212
/////**
1313
//// * @type {[|/*use*/Product|]}
@@ -18,11 +18,12 @@ const desc = `type Product = {
1818
title: string;
1919
}`;
2020

21+
const [r0Def, ...ranges] = test.ranges();
2122
verify.quickInfoAt("use", desc, "Doc comment");
2223

2324
verify.goToDefinition("use", "def");
2425

25-
verify.rangesAreOccurrences();
26-
verify.rangesAreDocumentHighlights();
27-
verify.singleReferenceGroup(desc);
28-
verify.rangesAreRenameLocations();
26+
verify.rangesAreOccurrences(/*isWriteAccesss*/ undefined, ranges);
27+
verify.rangesAreDocumentHighlights(ranges);
28+
verify.singleReferenceGroup(desc, ranges);
29+
verify.rangesAreRenameLocations(ranges);

tests/cases/fourslash/jsxSpreadReference.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
//// }
1515
//// }
1616
////
17-
//// var [|/*dst*/nn|]: {name?: string; size?: number};
17+
//// [|var [|/*dst*/{| "declarationRangeIndex": 0 |}nn|]: {name?: string; size?: number};|]
1818
//// var x = <MyClass {...[|n/*src*/n|]}></MyClass>;
1919

2020
verify.goToDefinition("src", "dst");
21-
verify.rangesAreRenameLocations();
21+
const [rDef, ...ranges] = test.ranges();
22+
verify.rangesAreRenameLocations(ranges);

tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
// @Filename: file1.ts
44
//// class Foo {
5-
//// constructor(private [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}privateParam|]: number,
6-
//// public [|{| "isWriteAccess": true, "isDefinition": true, "type": "string" |}publicParam|]: string,
7-
//// protected [|{| "isWriteAccess": true, "isDefinition": true, "type": "boolean" |}protectedParam|]: boolean) {
5+
//// constructor([|private [|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 0 |}privateParam|]: number|],
6+
//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "type": "string", "declarationRangeIndex": 2 |}publicParam|]: string|],
7+
//// [|protected [|{| "isWriteAccess": true, "isDefinition": true, "type": "boolean", "declarationRangeIndex": 4 |}protectedParam|]: boolean|]) {
88
////
99
//// let localPrivate = [|privateParam|];
1010
//// this.[|{| "isWriteAccess": true |}privateParam|] += 10;
@@ -18,6 +18,8 @@
1818
//// }
1919

2020
test.rangesByText().forEach((ranges, text) => {
21+
if (text !== "privateParam" && text !== "publicParam" && text !== "protectedParam") return;
22+
2123
const [r0, r1, r2] = ranges;
2224
const type = r0.marker.data.type;
2325
verify.referenceGroups(ranges, [

0 commit comments

Comments
 (0)