Skip to content

Commit 591f963

Browse files
committed
Add language service tests for this predicates
1 parent 58400ed commit 591f963

File tree

2 files changed

+232
-0
lines changed

2 files changed

+232
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// class RoyalGuard {
4+
//// isLeader(): this is LeadGuard {
5+
//// return this instanceof LeadGuard;
6+
//// }
7+
//// isFollower(): this is FollowerGuard {
8+
//// return this instanceof FollowerGuard;
9+
//// }
10+
//// }
11+
////
12+
//// class LeadGuard extends RoyalGuard {
13+
//// lead(): void {};
14+
//// }
15+
////
16+
//// class FollowerGuard extends RoyalGuard {
17+
//// follow(): void {};
18+
//// }
19+
////
20+
//// let a: RoyalGuard = new FollowerGuard();
21+
//// if (a.is/*1*/Leader()) {
22+
//// a./*2*/;
23+
//// }
24+
//// else if (a.is/*3*/Follower()) {
25+
//// a./*4*/;
26+
//// }
27+
////
28+
//// interface GuardInterface {
29+
//// isLeader(): this is LeadGuard;
30+
//// isFollower(): this is FollowerGuard;
31+
//// }
32+
////
33+
//// let b: GuardInterface;
34+
//// if (b.is/*5*/Leader()) {
35+
//// b./*6*/;
36+
//// }
37+
//// else if (b.is/*7*/Follower()) {
38+
//// b./*8*/;
39+
//// }
40+
////
41+
//// if (((a.isLeader)())) {
42+
//// a./*9*/;
43+
//// }
44+
//// else if (((a).isFollower())) {
45+
//// a./*10*/;
46+
//// }
47+
////
48+
//// if (((a["isLeader"])())) {
49+
//// a./*11*/;
50+
//// }
51+
//// else if (((a)["isFollower"]())) {
52+
//// a./*12*/;
53+
//// }
54+
////
55+
//// let leader/*13*/Status = a.isLeader();
56+
//// function isLeaderGuard(g: RoyalGuard) {
57+
//// return g.isLeader();
58+
//// }
59+
//// let checked/*14*/LeaderStatus = isLeader/*15*/Guard(a);
60+
61+
62+
goTo.marker("1");
63+
verify.quickInfoIs("(method) RoyalGuard.isLeader(): this is LeadGuard");
64+
goTo.marker("2");
65+
verify.completionListContains("lead");
66+
goTo.marker("3");
67+
verify.quickInfoIs("(method) RoyalGuard.isFollower(): this is FollowerGuard");
68+
goTo.marker("4");
69+
verify.completionListContains("follow");
70+
71+
goTo.marker("5");
72+
verify.quickInfoIs("(method) GuardInterface.isLeader(): this is LeadGuard");
73+
goTo.marker("6");
74+
verify.completionListContains("lead");
75+
goTo.marker("7");
76+
verify.quickInfoIs("(method) GuardInterface.isFollower(): this is FollowerGuard");
77+
goTo.marker("8");
78+
verify.completionListContains("follow");
79+
80+
goTo.marker("9");
81+
verify.completionListContains("lead");
82+
goTo.marker("10");
83+
verify.completionListContains("follow");
84+
85+
goTo.marker("11");
86+
verify.completionListContains("lead");
87+
goTo.marker("12");
88+
verify.completionListContains("follow");
89+
90+
goTo.marker("13");
91+
verify.quickInfoIs("let leaderStatus: boolean");
92+
goTo.marker("14");
93+
verify.quickInfoIs("let checkedLeaderStatus: boolean");
94+
goTo.marker("15");
95+
verify.quickInfoIs("function isLeaderGuard(g: RoyalGuard): boolean");
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// class FileSystemObject {
4+
//// get is/*1*/File(): this is Item {
5+
//// return this instanceof Item;
6+
//// }
7+
//// set is/*2*/File(param) {
8+
//// // noop
9+
//// }
10+
//// get is/*3*/Directory(): this is Directory {
11+
//// return this instanceof Directory;
12+
//// }
13+
//// is/*4*/Networked: this is (Networked & this);
14+
//// constructor(public path: string) {}
15+
//// }
16+
////
17+
//// class Item extends FileSystemObject {
18+
//// constructor(path: string, public content: string) { super(path); }
19+
//// }
20+
//// class Directory extends FileSystemObject {
21+
//// children: FileSystemObject[];
22+
//// }
23+
//// interface Networked {
24+
//// host: string;
25+
//// }
26+
////
27+
//// interface Sundries {
28+
//// broken: boolean;
29+
//// }
30+
////
31+
//// interface Supplies {
32+
//// spoiled: boolean;
33+
//// }
34+
////
35+
//// interface Crate<T> {
36+
//// contents: T;
37+
//// is/*5*/Sundries: this is Crate<Sundries>;
38+
//// is/*6*/Supplies: this is Crate<Supplies>;
39+
//// is/*7*/PackedTight: this is (this & {extraContents: T});
40+
//// }
41+
////
42+
//// const obj: FileSystemObject = new Item("/foo", "");
43+
//// if (obj.is/*8*/File) {
44+
//// obj./*9*/;
45+
//// if (obj.is/*10*/Networked) {
46+
//// obj./*11*/;
47+
//// }
48+
//// }
49+
//// if (obj.is/*12*/Directory) {
50+
//// obj./*13*/;
51+
//// if (obj.is/*14*/Networked) {
52+
//// obj./*15*/;
53+
//// }
54+
//// }
55+
//// if (obj.is/*16*/Networked) {
56+
//// obj./*17*/;
57+
//// }
58+
////
59+
//// const crate: Crate<any>;
60+
//// if (crate.is/*18*/PackedTight) {
61+
//// crate./*19*/;
62+
//// }
63+
//// if (crate.is/*20*/Sundries) {
64+
//// crate.contents./*21*/;
65+
//// if (crate.is/*22*/PackedTight) {
66+
//// crate./*23*/
67+
//// }
68+
//// }
69+
//// if (crate.is/*24*/Supplies) {
70+
//// crate.contents./*25*/;
71+
//// if (crate.is/*26*/PackedTight) {
72+
//// crate./*27*/
73+
//// }
74+
//// }
75+
76+
goTo.marker("1");
77+
verify.quickInfoIs("(property) FileSystemObject.isFile: this is Item");
78+
goTo.marker("2");
79+
verify.quickInfoIs("(property) FileSystemObject.isFile: this is Item");
80+
goTo.marker("3");
81+
verify.quickInfoIs("(property) FileSystemObject.isDirectory: this is Directory");
82+
goTo.marker("4");
83+
verify.quickInfoIs("(property) FileSystemObject.isNetworked: this is Networked & this");
84+
goTo.marker("5");
85+
verify.quickInfoIs("(property) Crate<T>.isSundries: this is Crate<Sundries>");
86+
goTo.marker("6");
87+
verify.quickInfoIs("(property) Crate<T>.isSupplies: this is Crate<Supplies>");
88+
goTo.marker("7");
89+
verify.quickInfoIs(`(property) Crate<T>.isPackedTight: this is this & {
90+
extraContents: T;
91+
}`);
92+
goTo.marker("8");
93+
verify.quickInfoIs("(property) FileSystemObject.isFile: this is Item");
94+
goTo.marker("9");
95+
verify.completionListContains("content");
96+
goTo.marker("10");
97+
verify.quickInfoIs("(property) FileSystemObject.isNetworked: this is Networked & Item");
98+
goTo.marker("11");
99+
verify.completionListContains("host");
100+
goTo.marker("12");
101+
verify.quickInfoIs("(property) FileSystemObject.isDirectory: this is Directory");
102+
goTo.marker("13");
103+
verify.completionListContains("children");
104+
goTo.marker("14");
105+
verify.quickInfoIs("(property) FileSystemObject.isNetworked: this is Networked & Directory");
106+
goTo.marker("15");
107+
verify.completionListContains("host");
108+
goTo.marker("16");
109+
verify.quickInfoIs("(property) FileSystemObject.isNetworked: this is Networked & FileSystemObject");
110+
goTo.marker("17");
111+
verify.completionListContains("host");
112+
goTo.marker("18");
113+
verify.quickInfoIs(`(property) Crate<any>.isPackedTight: this is Crate<any> & {
114+
extraContents: any;
115+
}`);
116+
goTo.marker("19");
117+
verify.completionListContains("extraContents");
118+
goTo.marker("20");
119+
verify.quickInfoIs("(property) Crate<any>.isSundries: this is Crate<Sundries>");
120+
goTo.marker("21");
121+
verify.completionListContains("broken");
122+
goTo.marker("22");
123+
verify.quickInfoIs(`(property) Crate<Sundries>.isPackedTight: this is Crate<Sundries> & {
124+
extraContents: Sundries;
125+
}`);
126+
goTo.marker("23");
127+
verify.completionListContains("extraContents");
128+
goTo.marker("24");
129+
verify.quickInfoIs("(property) Crate<any>.isSupplies: this is Crate<Supplies>");
130+
goTo.marker("25");
131+
verify.completionListContains("spoiled");
132+
goTo.marker("26");
133+
verify.quickInfoIs(`(property) Crate<Supplies>.isPackedTight: this is Crate<Supplies> & {
134+
extraContents: Supplies;
135+
}`);
136+
goTo.marker("27");
137+
verify.completionListContains("extraContents");

0 commit comments

Comments
 (0)