Skip to content

Commit 3d19782

Browse files
author
Kanchalai Tanglertsampan
committed
Add language service tests
1 parent 2c15eab commit 3d19782

32 files changed

+986
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// interface PropsBag {
4+
//// /*first*/propx: number
5+
//// }
6+
//// function foo(arg: PropsBag) {}
7+
//// foo({
8+
//// pr/*p1*/opx: 10
9+
//// })
10+
//// function bar(firstarg: boolean, secondarg: PropsBag) {}
11+
//// bar(true, {
12+
//// pr/*p2*/opx: 10
13+
//// })
14+
15+
16+
verify.goToDefinition({
17+
p1: "first",
18+
p2: "first"
19+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
// @jsx: preserve
5+
// @noLib: true
6+
7+
//// declare module JSX {
8+
//// interface Element { }
9+
//// interface IntrinsicElements {
10+
//// }
11+
//// interface ElementAttributesProperty { props; }
12+
//// }
13+
//// interface OptionPropBag {
14+
//// propx: number
15+
//// propString: "hell"
16+
//// optional?: boolean
17+
//// }
18+
//// declare function Opt(attributes: OptionPropBag): JSX.Element;
19+
//// let opt = <Opt /*1*/ />;
20+
//// let opt1 = <Opt prop/*2*/ />;
21+
//// let opt2 = <Opt propx={100} /*3*/ />;
22+
//// let opt3 = <Opt propx={100} optional /*4*/ />;
23+
//// let opt4 = <Opt wrong /*5*/ />;
24+
25+
goTo.marker("1");
26+
verify.completionListContains('propx');
27+
verify.completionListContains('propString');
28+
verify.completionListContains('optional');
29+
30+
goTo.marker("2");
31+
verify.completionListContains('propx');
32+
verify.completionListContains('propString');
33+
34+
goTo.marker("3");
35+
verify.completionListContains("propString")
36+
verify.completionListContains("optional")
37+
verify.not.completionListContains("propx")
38+
39+
goTo.marker("4");
40+
verify.completionListContains("propString");
41+
verify.not.completionListContains("propx");
42+
verify.not.completionListContains("optional");
43+
44+
goTo.marker("5");
45+
verify.completionListContains('propx');
46+
verify.completionListContains('propString');
47+
verify.completionListContains('optional');
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
// @jsx: preserve
5+
// @noLib: true
6+
7+
//// declare module JSX {
8+
//// interface Element { }
9+
//// interface IntrinsicElements {
10+
//// }
11+
//// interface ElementAttributesProperty { props; }
12+
//// }
13+
//// interface ClickableProps {
14+
//// children?: string;
15+
//// className?: string;
16+
//// }
17+
//// interface ButtonProps extends ClickableProps {
18+
//// onClick(event?: React.MouseEvent<HTMLButtonElement>): void;
19+
//// }
20+
//// interface LinkProps extends ClickableProps {
21+
//// goTo: string;
22+
//// }
23+
//// declare function MainButton(buttonProps: ButtonProps): JSX.Element;
24+
//// declare function MainButton(linkProps: LinkProps): JSX.Element;
25+
//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element;
26+
//// let opt = <MainButton /*1*/ />;
27+
//// let opt = <MainButton children="chidlren" /*2*/ />;
28+
//// let opt = <MainButton onClick={()=>{}} /*3*/ />;
29+
//// let opt = <MainButton onClick={()=>{}} ignore-prop /*4*/ />;
30+
//// let opt = <MainButton goTo="goTo" /*5*/ />;
31+
//// let opt = <MainButton wrong /*6*/ />;
32+
33+
goTo.marker("1");
34+
verify.completionListContains('children');
35+
verify.completionListContains('className');
36+
verify.completionListContains('onClick');
37+
verify.completionListContains('goTo');
38+
39+
goTo.marker("2");
40+
verify.completionListContains('className');
41+
verify.completionListContains('onClick');
42+
verify.completionListContains('goTo');
43+
44+
goTo.marker("3");
45+
verify.completionListContains('children');
46+
verify.completionListContains('className');
47+
verify.not.completionListContains('goTo');
48+
49+
goTo.marker("4");
50+
verify.completionListContains('children');
51+
verify.completionListContains('className');
52+
53+
goTo.marker("5");
54+
verify.completionListContains('children');
55+
verify.completionListContains('className');
56+
verify.not.completionListContains('onClick');
57+
58+
goTo.marker("6");
59+
verify.completionListContains('children');
60+
verify.completionListContains('className');
61+
verify.completionListContains('onClick');
62+
verify.completionListContains('goTo');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
//// declare module JSX {
5+
//// interface Element { }
6+
//// interface IntrinsicElements {
7+
//// [|div|]: {
8+
//// name?: string;
9+
//// isOpen?: boolean;
10+
//// };
11+
//// span: { n: string; };
12+
//// }
13+
//// }
14+
//// var x = <[|div|] />;
15+
16+
verify.rangesReferenceEachOther();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
// @jsx: preserve
5+
// @noLib: true
6+
7+
//// declare module JSX {
8+
//// interface Element { }
9+
//// interface IntrinsicElements {
10+
//// }
11+
//// interface ElementAttributesProperty { props; }
12+
//// }
13+
//// interface ClickableProps {
14+
//// children?: string;
15+
//// className?: string;
16+
//// }
17+
//// interface ButtonProps extends ClickableProps {
18+
//// [|onClick|](event?: React.MouseEvent<HTMLButtonElement>): void;
19+
//// }
20+
//// interface LinkProps extends ClickableProps {
21+
//// goTo: string;
22+
//// }
23+
//// declare function MainButton(buttonProps: ButtonProps): JSX.Element;
24+
//// declare function MainButton(linkProps: LinkProps): JSX.Element;
25+
//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element;
26+
//// let opt = <MainButton />;
27+
//// let opt = <MainButton children="chidlren" />;
28+
//// let opt = <MainButton [|onClick|]={()=>{}} />;
29+
//// let opt = <MainButton [|onClick|]={()=>{}} ignore-prop />;
30+
//// let opt = <MainButton goTo="goTo" />;
31+
//// let opt = <MainButton wrong />;
32+
33+
verify.rangesReferenceEachOther();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
// @jsx: preserve
5+
// @noLib: true
6+
7+
//// declare module JSX {
8+
//// interface Element { }
9+
//// interface IntrinsicElements {
10+
//// }
11+
//// interface ElementAttributesProperty { props; }
12+
//// }
13+
//// interface ClickableProps {
14+
//// children?: string;
15+
//// className?: string;
16+
//// }
17+
//// interface ButtonProps extends ClickableProps {
18+
//// onClick(event?: React.MouseEvent<HTMLButtonElement>): void;
19+
//// }
20+
//// interface LinkProps extends ClickableProps {
21+
//// goTo: string;
22+
//// }
23+
//// declare function MainButton(buttonProps: ButtonProps): JSX.Element;
24+
//// declare function MainButton(linkProps: LinkProps): JSX.Element;
25+
//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element;
26+
//// let opt = <MainButton [|wrong|] />; // r1
27+
28+
const [r1] = test.ranges();
29+
verify.referencesOf(r1, [r1]);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
//// declare module JSX {
5+
//// interface Element { }
6+
//// interface IntrinsicElements {
7+
//// div: {
8+
//// [|name|]?: string;
9+
//// isOpen?: boolean;
10+
//// };
11+
//// span: { n: string; };
12+
//// }
13+
//// }
14+
//// var x = <div [|name|]="hello" />;
15+
16+
verify.rangesReferenceEachOther();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
//// declare module JSX {
5+
//// interface Element { }
6+
//// interface IntrinsicElements {
7+
//// }
8+
//// interface ElementAttributesProperty { props }
9+
//// }
10+
//// class MyClass {
11+
//// props: {
12+
//// [|name|]?: string;
13+
//// size?: number;
14+
//// }
15+
////
16+
////
17+
//// var x = <MyClass [|name|]='hello'/>;
18+
19+
verify.rangesReferenceEachOther();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
//// declare module JSX {
5+
//// interface Element { }
6+
//// interface IntrinsicElements {
7+
//// }
8+
//// interface ElementAttributesProperty { props }
9+
//// }
10+
//// class [|MyClass|] {
11+
//// props: {
12+
//// name?: string;
13+
//// size?: number;
14+
//// }
15+
////
16+
////
17+
//// var x = <[|MyClass|] name='hello'></[|MyClass|]>;
18+
19+
verify.rangesReferenceEachOther();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: file.tsx
4+
// @jsx: preserve
5+
// @noLib: true
6+
7+
//// declare module JSX {
8+
//// interface Element { }
9+
//// interface IntrinsicElements {
10+
//// }
11+
//// interface ElementAttributesProperty { props; }
12+
//// }
13+
//// interface OptionPropBag {
14+
//// propx: number
15+
//// propString: string
16+
//// optional?: boolean
17+
//// }
18+
//// declare function [|Opt|](attributes: OptionPropBag): JSX.Element;
19+
//// let opt = <[|Opt|] />;
20+
//// let opt1 = <[|Opt|] propx={100} propString />;
21+
//// let opt2 = <[|Opt|] propx={100} optional/>;
22+
//// let opt3 = <[|Opt|] wrong />;
23+
//// let opt4 = <[|Opt|] propx={100} propString="hi" />;
24+
25+
verify.rangesReferenceEachOther();

0 commit comments

Comments
 (0)