From 3d19782b1c52ff62e094b8e8f7d69087647dd6fc Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 8 Nov 2016 11:07:17 -0800 Subject: [PATCH] Add language service tests --- .../goToDefinitionObjectLiteralProperties1.ts | 19 ++++++ tests/cases/fourslash/tsxCompletion12.ts | 47 ++++++++++++++ tests/cases/fourslash/tsxCompletion13.ts | 62 +++++++++++++++++++ .../cases/fourslash/tsxFindAllReferences1.ts | 16 +++++ .../cases/fourslash/tsxFindAllReferences10.ts | 33 ++++++++++ .../cases/fourslash/tsxFindAllReferences11.ts | 29 +++++++++ .../cases/fourslash/tsxFindAllReferences2.ts | 16 +++++ .../cases/fourslash/tsxFindAllReferences3.ts | 19 ++++++ .../cases/fourslash/tsxFindAllReferences4.ts | 19 ++++++ .../cases/fourslash/tsxFindAllReferences5.ts | 25 ++++++++ .../cases/fourslash/tsxFindAllReferences6.ts | 23 +++++++ .../cases/fourslash/tsxFindAllReferences7.ts | 24 +++++++ .../cases/fourslash/tsxFindAllReferences8.ts | 33 ++++++++++ .../cases/fourslash/tsxFindAllReferences9.ts | 34 ++++++++++ .../fourslash/tsxGoToDefinitionClasses.ts | 4 +- .../tsxGoToDefinitionStatelessFunction1.ts | 31 ++++++++++ .../tsxGoToDefinitionStatelessFunction2.ts | 40 ++++++++++++ tests/cases/fourslash/tsxQuickInfo3.ts | 30 +++++++++ tests/cases/fourslash/tsxQuickInfo4.ts | 55 ++++++++++++++++ tests/cases/fourslash/tsxQuickInfo5.ts | 18 ++++++ tests/cases/fourslash/tsxQuickInfo6.ts | 19 ++++++ tests/cases/fourslash/tsxQuickInfo7.ts | 29 +++++++++ tests/cases/fourslash/tsxRename10.ts | 40 ++++++++++++ tests/cases/fourslash/tsxRename11.ts | 39 ++++++++++++ tests/cases/fourslash/tsxRename12.ts | 39 ++++++++++++ tests/cases/fourslash/tsxRename13.ts | 39 ++++++++++++ tests/cases/fourslash/tsxRename6.ts | 30 +++++++++ tests/cases/fourslash/tsxRename7.ts | 29 +++++++++ tests/cases/fourslash/tsxRename8.ts | 31 ++++++++++ tests/cases/fourslash/tsxRename9.ts | 38 ++++++++++++ tests/cases/fourslash/tsxSignatureHelp1.ts | 35 +++++++++++ tests/cases/fourslash/tsxSignatureHelp2.ts | 42 +++++++++++++ 32 files changed, 986 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/goToDefinitionObjectLiteralProperties1.ts create mode 100644 tests/cases/fourslash/tsxCompletion12.ts create mode 100644 tests/cases/fourslash/tsxCompletion13.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences1.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences10.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences11.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences2.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences3.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences4.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences5.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences6.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences7.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences8.ts create mode 100644 tests/cases/fourslash/tsxFindAllReferences9.ts create mode 100644 tests/cases/fourslash/tsxGoToDefinitionStatelessFunction1.ts create mode 100644 tests/cases/fourslash/tsxGoToDefinitionStatelessFunction2.ts create mode 100644 tests/cases/fourslash/tsxQuickInfo3.ts create mode 100644 tests/cases/fourslash/tsxQuickInfo4.ts create mode 100644 tests/cases/fourslash/tsxQuickInfo5.ts create mode 100644 tests/cases/fourslash/tsxQuickInfo6.ts create mode 100644 tests/cases/fourslash/tsxQuickInfo7.ts create mode 100644 tests/cases/fourslash/tsxRename10.ts create mode 100644 tests/cases/fourslash/tsxRename11.ts create mode 100644 tests/cases/fourslash/tsxRename12.ts create mode 100644 tests/cases/fourslash/tsxRename13.ts create mode 100644 tests/cases/fourslash/tsxRename6.ts create mode 100644 tests/cases/fourslash/tsxRename7.ts create mode 100644 tests/cases/fourslash/tsxRename8.ts create mode 100644 tests/cases/fourslash/tsxRename9.ts create mode 100644 tests/cases/fourslash/tsxSignatureHelp1.ts create mode 100644 tests/cases/fourslash/tsxSignatureHelp2.ts diff --git a/tests/cases/fourslash/goToDefinitionObjectLiteralProperties1.ts b/tests/cases/fourslash/goToDefinitionObjectLiteralProperties1.ts new file mode 100644 index 00000000000..a1c22ca4ca3 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionObjectLiteralProperties1.ts @@ -0,0 +1,19 @@ +/// + +//// interface PropsBag { +//// /*first*/propx: number +//// } +//// function foo(arg: PropsBag) {} +//// foo({ +//// pr/*p1*/opx: 10 +//// }) +//// function bar(firstarg: boolean, secondarg: PropsBag) {} +//// bar(true, { +//// pr/*p2*/opx: 10 +//// }) + + +verify.goToDefinition({ + p1: "first", + p2: "first" +}); diff --git a/tests/cases/fourslash/tsxCompletion12.ts b/tests/cases/fourslash/tsxCompletion12.ts new file mode 100644 index 00000000000..542dbec2c2b --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion12.ts @@ -0,0 +1,47 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface OptionPropBag { +//// propx: number +//// propString: "hell" +//// optional?: boolean +//// } +//// declare function Opt(attributes: OptionPropBag): JSX.Element; +//// let opt = ; +//// let opt1 = ; +//// let opt2 = ; +//// let opt3 = ; +//// let opt4 = ; + +goTo.marker("1"); +verify.completionListContains('propx'); +verify.completionListContains('propString'); +verify.completionListContains('optional'); + +goTo.marker("2"); +verify.completionListContains('propx'); +verify.completionListContains('propString'); + +goTo.marker("3"); +verify.completionListContains("propString") +verify.completionListContains("optional") +verify.not.completionListContains("propx") + +goTo.marker("4"); +verify.completionListContains("propString"); +verify.not.completionListContains("propx"); +verify.not.completionListContains("optional"); + +goTo.marker("5"); +verify.completionListContains('propx'); +verify.completionListContains('propString'); +verify.completionListContains('optional'); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxCompletion13.ts b/tests/cases/fourslash/tsxCompletion13.ts new file mode 100644 index 00000000000..60964acbc55 --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion13.ts @@ -0,0 +1,62 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// goTo: string; +//// } +//// declare function MainButton(buttonProps: ButtonProps): JSX.Element; +//// declare function MainButton(linkProps: LinkProps): JSX.Element; +//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element; +//// let opt = ; +//// let opt = ; +//// let opt = {}} /*3*/ />; +//// let opt = {}} ignore-prop /*4*/ />; +//// let opt = ; +//// let opt = ; + +goTo.marker("1"); +verify.completionListContains('children'); +verify.completionListContains('className'); +verify.completionListContains('onClick'); +verify.completionListContains('goTo'); + +goTo.marker("2"); +verify.completionListContains('className'); +verify.completionListContains('onClick'); +verify.completionListContains('goTo'); + +goTo.marker("3"); +verify.completionListContains('children'); +verify.completionListContains('className'); +verify.not.completionListContains('goTo'); + +goTo.marker("4"); +verify.completionListContains('children'); +verify.completionListContains('className'); + +goTo.marker("5"); +verify.completionListContains('children'); +verify.completionListContains('className'); +verify.not.completionListContains('onClick'); + +goTo.marker("6"); +verify.completionListContains('children'); +verify.completionListContains('className'); +verify.completionListContains('onClick'); +verify.completionListContains('goTo'); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences1.ts b/tests/cases/fourslash/tsxFindAllReferences1.ts new file mode 100644 index 00000000000..9b55901ba68 --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences1.ts @@ -0,0 +1,16 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// [|div|]: { +//// name?: string; +//// isOpen?: boolean; +//// }; +//// span: { n: string; }; +//// } +//// } +//// var x = <[|div|] />; + +verify.rangesReferenceEachOther(); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences10.ts b/tests/cases/fourslash/tsxFindAllReferences10.ts new file mode 100644 index 00000000000..a027671ec3d --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences10.ts @@ -0,0 +1,33 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// [|onClick|](event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// goTo: string; +//// } +//// declare function MainButton(buttonProps: ButtonProps): JSX.Element; +//// declare function MainButton(linkProps: LinkProps): JSX.Element; +//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element; +//// let opt = ; +//// let opt = ; +//// let opt = {}} />; +//// let opt = {}} ignore-prop />; +//// let opt = ; +//// let opt = ; + +verify.rangesReferenceEachOther(); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences11.ts b/tests/cases/fourslash/tsxFindAllReferences11.ts new file mode 100644 index 00000000000..ef2f7722243 --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences11.ts @@ -0,0 +1,29 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// goTo: string; +//// } +//// declare function MainButton(buttonProps: ButtonProps): JSX.Element; +//// declare function MainButton(linkProps: LinkProps): JSX.Element; +//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element; +//// let opt = ; // r1 + +const [r1] = test.ranges(); +verify.referencesOf(r1, [r1]); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences2.ts b/tests/cases/fourslash/tsxFindAllReferences2.ts new file mode 100644 index 00000000000..8522874865a --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences2.ts @@ -0,0 +1,16 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// div: { +//// [|name|]?: string; +//// isOpen?: boolean; +//// }; +//// span: { n: string; }; +//// } +//// } +//// var x =
; + +verify.rangesReferenceEachOther(); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences3.ts b/tests/cases/fourslash/tsxFindAllReferences3.ts new file mode 100644 index 00000000000..2f78cc08ba9 --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences3.ts @@ -0,0 +1,19 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props } +//// } +//// class MyClass { +//// props: { +//// [|name|]?: string; +//// size?: number; +//// } +//// +//// +//// var x = ; + +verify.rangesReferenceEachOther(); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences4.ts b/tests/cases/fourslash/tsxFindAllReferences4.ts new file mode 100644 index 00000000000..a1309bfaef9 --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences4.ts @@ -0,0 +1,19 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props } +//// } +//// class [|MyClass|] { +//// props: { +//// name?: string; +//// size?: number; +//// } +//// +//// +//// var x = <[|MyClass|] name='hello'>; + +verify.rangesReferenceEachOther(); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences5.ts b/tests/cases/fourslash/tsxFindAllReferences5.ts new file mode 100644 index 00000000000..018b7568df1 --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences5.ts @@ -0,0 +1,25 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface OptionPropBag { +//// propx: number +//// propString: string +//// optional?: boolean +//// } +//// declare function [|Opt|](attributes: OptionPropBag): JSX.Element; +//// let opt = <[|Opt|] />; +//// let opt1 = <[|Opt|] propx={100} propString />; +//// let opt2 = <[|Opt|] propx={100} optional/>; +//// let opt3 = <[|Opt|] wrong />; +//// let opt4 = <[|Opt|] propx={100} propString="hi" />; + +verify.rangesReferenceEachOther(); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences6.ts b/tests/cases/fourslash/tsxFindAllReferences6.ts new file mode 100644 index 00000000000..ad689a53baf --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences6.ts @@ -0,0 +1,23 @@ +/// +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface OptionPropBag { +//// propx: number +//// propString: string +//// optional?: boolean +//// } +//// declare function Opt(attributes: OptionPropBag): JSX.Element; +//// let opt = ; //r1 + +const [r1] = test.ranges(); +verify.referencesOf(r1, [r1]); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences7.ts b/tests/cases/fourslash/tsxFindAllReferences7.ts new file mode 100644 index 00000000000..b1f5231a198 --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences7.ts @@ -0,0 +1,24 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface OptionPropBag { +//// [|propx|]: number +//// propString: string +//// optional?: boolean +//// } +//// declare function Opt(attributes: OptionPropBag): JSX.Element; +//// let opt = ; +//// let opt1 = ; +//// let opt2 = ; +//// let opt3 = ; + +verify.rangesReferenceEachOther(); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences8.ts b/tests/cases/fourslash/tsxFindAllReferences8.ts new file mode 100644 index 00000000000..434e8cf3303 --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences8.ts @@ -0,0 +1,33 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// goTo: string; +//// } +//// declare function [|MainButton|](buttonProps: ButtonProps): JSX.Element; +//// declare function [|MainButton|](linkProps: LinkProps): JSX.Element; +//// declare function [|MainButton|](props: ButtonProps | LinkProps): JSX.Element; +//// let opt = <[|MainButton|] />; +//// let opt = <[|MainButton|] children="chidlren" />; +//// let opt = <[|MainButton|] onClick={()=>{}} />; +//// let opt = <[|MainButton|] onClick={()=>{}} ignore-prop />; +//// let opt = <[|MainButton|] goTo="goTo" />; +//// let opt = <[|MainButton|] wrong />; + +verify.rangesReferenceEachOther(); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences9.ts b/tests/cases/fourslash/tsxFindAllReferences9.ts new file mode 100644 index 00000000000..5ac6ad344d8 --- /dev/null +++ b/tests/cases/fourslash/tsxFindAllReferences9.ts @@ -0,0 +1,34 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// [|goTo|]: string; +//// } +//// declare function MainButton(buttonProps: ButtonProps): JSX.Element; +//// declare function MainButton(linkProps: LinkProps): JSX.Element; +//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element; +//// let opt = ; +//// let opt = ; +//// let opt = {}} />; +//// let opt = {}} ignore-prop />; +//// let opt = ; +//// let opt = ; +//// let opt = ; + +verify.rangesReferenceEachOther(); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxGoToDefinitionClasses.ts b/tests/cases/fourslash/tsxGoToDefinitionClasses.ts index fb76080f6df..688ce879adf 100644 --- a/tests/cases/fourslash/tsxGoToDefinitionClasses.ts +++ b/tests/cases/fourslash/tsxGoToDefinitionClasses.ts @@ -13,8 +13,10 @@ //// } //// var x = ; //// var y = ; +//// var z = ; verify.goToDefinition({ c: "ct", - p: "pt" + p: "pt", + w: "ct" }); diff --git a/tests/cases/fourslash/tsxGoToDefinitionStatelessFunction1.ts b/tests/cases/fourslash/tsxGoToDefinitionStatelessFunction1.ts new file mode 100644 index 00000000000..d715dc5b204 --- /dev/null +++ b/tests/cases/fourslash/tsxGoToDefinitionStatelessFunction1.ts @@ -0,0 +1,31 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface OptionPropBag { +//// /*pt1*/propx: number +//// propString: "hell" +//// /*pt2*/optional?: boolean +//// } +//// /*opt*/declare function Opt(attributes: OptionPropBag): JSX.Element; +//// let opt = ; +//// let opt1 = ; +//// let opt2 = ; +//// let opt3 = ; + +verify.goToDefinition({ + one: "opt", + two: "opt", + three: "opt", + four: "opt", + p1: "pt1", + p2: "pt2" +}); diff --git a/tests/cases/fourslash/tsxGoToDefinitionStatelessFunction2.ts b/tests/cases/fourslash/tsxGoToDefinitionStatelessFunction2.ts new file mode 100644 index 00000000000..77eb0864828 --- /dev/null +++ b/tests/cases/fourslash/tsxGoToDefinitionStatelessFunction2.ts @@ -0,0 +1,40 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// goTo: string; +//// } +//// /*firstSource*/declare function MainButton(buttonProps: ButtonProps): JSX.Element; +//// /*secondSource*/declare function MainButton(linkProps: LinkProps): JSX.Element; +//// /*thirdSource*/declare function MainButton(props: ButtonProps | LinkProps): JSX.Element; +//// let opt =
; +//// let opt =
; +//// let opt =
{}} />; +//// let opt =
{}} ignore-prop />; +//// let opt =
; +//// let opt =
; + +verify.goToDefinition({ + firstTarget: "firstSource", + secondTarget: "firstSource", + thirdTarget: "firstSource", + fourthTarget: "firstSource", + fivethTarget: "secondSource", + sixthTarget: "firstSource" +}); diff --git a/tests/cases/fourslash/tsxQuickInfo3.ts b/tests/cases/fourslash/tsxQuickInfo3.ts new file mode 100644 index 00000000000..614ffa878ef --- /dev/null +++ b/tests/cases/fourslash/tsxQuickInfo3.ts @@ -0,0 +1,30 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// interface OptionProp { +//// propx: 2 +//// } + +//// class Opt extends React.Component { +//// render() { +//// return
Hello
; +//// } +//// } + +//// const obj1: OptionProp = { +//// propx: 2 +//// } + +//// let y1 = ; +//// let y2 = ; +//// let y2 = ; + +verify.quickInfos({ + 1: "class Opt", + 2: "(JSX attribute) propx: number", + 3: "const obj1: OptionProp", + 4: "(JSX attribute) propx: true" +}); diff --git a/tests/cases/fourslash/tsxQuickInfo4.ts b/tests/cases/fourslash/tsxQuickInfo4.ts new file mode 100644 index 00000000000..d9f566571aa --- /dev/null +++ b/tests/cases/fourslash/tsxQuickInfo4.ts @@ -0,0 +1,55 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// export interface ClickableProps { +//// children?: string; +//// className?: string; +//// } + +//// export interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } + +//// export interface LinkProps extends ClickableProps { +//// to: string; +//// } + +//// export function MainButton(buttonProps: ButtonProps): JSX.Element; +//// export function MainButton(linkProps: LinkProps): JSX.Element; +//// export function MainButton(props: ButtonProps | LinkProps): JSX.Element { +//// const linkProps = props as LinkProps; +//// if(linkProps.to) { +//// return this._buildMainLink(props); +//// } +//// return this._buildMainButton(props); +//// } + +//// function _buildMainButton({ onClick, children, className }: ButtonProps): JSX.Element { +//// return(); +//// } + +//// declare function buildMainLink({ to, children, className }: LinkProps): JSX.Element; + +//// function buildSomeElement1(): JSX.Element { +//// return ( +//// GO +//// ); +//// } + +//// function buildSomeElement2(): JSX.Element { +//// return ( +//// {}}>GO; +//// ); +//// } +//// let componenet = {}} ext/*5*/ra-prop>GO; + +verify.quickInfos({ + 1: "function MainButton(linkProps: LinkProps): any (+1 overload)", + 2: "(JSX attribute) to: string", + 3: "function MainButton(buttonProps: ButtonProps): any (+1 overload)", + 4: "(JSX attribute) onClick: () => void", + 5: "(JSX attribute) extra-prop: true" +}); diff --git a/tests/cases/fourslash/tsxQuickInfo5.ts b/tests/cases/fourslash/tsxQuickInfo5.ts new file mode 100644 index 00000000000..cbdecb67da7 --- /dev/null +++ b/tests/cases/fourslash/tsxQuickInfo5.ts @@ -0,0 +1,18 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare function ComponentWithTwoAttributes(l: {key1: K, value: V}): JSX.Element; + +//// function Baz(key1: T, value: U) { +//// let a0 = +//// let a1 = +//// } + +verify.quickInfos({ + 1: "function ComponentWithTwoAttributes(l: {\n key1: T;\n value: U;\n}): any", + 2: "(JSX attribute) key1: T", + 3: "(JSX attribute) value: U", +}); diff --git a/tests/cases/fourslash/tsxQuickInfo6.ts b/tests/cases/fourslash/tsxQuickInfo6.ts new file mode 100644 index 00000000000..e121e52c0aa --- /dev/null +++ b/tests/cases/fourslash/tsxQuickInfo6.ts @@ -0,0 +1,19 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare function ComponentSpecific(l: {prop: U}): JSX.Element; +//// declare function ComponentSpecific1(l: {prop: U, "ignore-prop": number}): JSX.Element; + +//// function Bar(arg: T) { +//// let a1 = ; // U is number +//// let a2 = ; // U is number +//// let a3 = ; // U is "hello" +//// } + +verify.quickInfos({ + 1: "function ComponentSpecific<{}>(l: {\n prop: {};\n}): any", + 2: "function ComponentSpecific<{}>(l: {\n prop: {};\n}): any" +}); diff --git a/tests/cases/fourslash/tsxQuickInfo7.ts b/tests/cases/fourslash/tsxQuickInfo7.ts new file mode 100644 index 00000000000..ca90d83d719 --- /dev/null +++ b/tests/cases/fourslash/tsxQuickInfo7.ts @@ -0,0 +1,29 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare function OverloadComponent(): JSX.Element; +//// declare function OverloadComponent(attr: {b: U, a?: string, "ignore-prop": boolean}): JSX.Element; +//// declare function OverloadComponent(attr: {b: U, a: T}): JSX.Element; + +//// function Baz(arg1: T, arg2: U) { +//// let a0 = ; +//// let a1 = ; +//// let a2 = ; +//// let a3 = ; +//// let a4 = ; +//// let a5 = ; +//// let a6 = ; +//// } + +verify.quickInfos({ + 1: "function OverloadComponent(): any (+2 overloads)", + 2: "function OverloadComponent(): any (+2 overloads)", + 3: "function OverloadComponent(): any (+2 overloads)", + 4: "function OverloadComponent(): any (+2 overloads)", + 5: "function OverloadComponent(): any (+2 overloads)", + 6: "function OverloadComponent(): any (+2 overloads)", + 7: "function OverloadComponent(): any (+2 overloads)" +}); diff --git a/tests/cases/fourslash/tsxRename10.ts b/tests/cases/fourslash/tsxRename10.ts new file mode 100644 index 00000000000..091f5aa976f --- /dev/null +++ b/tests/cases/fourslash/tsxRename10.ts @@ -0,0 +1,40 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// [|goTo|]: string; +//// } +//// declare function MainButton(buttonProps: ButtonProps): JSX.Element; +//// declare function MainButton(linkProps: LinkProps): JSX.Element; +//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element; +//// let opt = ; +//// let opt = ; +//// let opt = {}} />; +//// let opt = {}} ignore-prop />; +//// let opt = ; +//// let opt = ; +//// let opt = ; + + +let ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/tsxRename11.ts b/tests/cases/fourslash/tsxRename11.ts new file mode 100644 index 00000000000..97933dd0cc9 --- /dev/null +++ b/tests/cases/fourslash/tsxRename11.ts @@ -0,0 +1,39 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// [|onClick|](event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// goTo: string; +//// } +//// declare function MainButton(buttonProps: ButtonProps): JSX.Element; +//// declare function MainButton(linkProps: LinkProps): JSX.Element; +//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element; +//// let opt = ; +//// let opt = ; +//// let opt = {}} />; +//// let opt = {}} ignore-prop />; +//// let opt = ; +//// let opt = ; + + +let ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/tsxRename12.ts b/tests/cases/fourslash/tsxRename12.ts new file mode 100644 index 00000000000..30e6b506f4d --- /dev/null +++ b/tests/cases/fourslash/tsxRename12.ts @@ -0,0 +1,39 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// goTo: string; +//// } +//// declare function MainButton(buttonProps: ButtonProps): JSX.Element; +//// declare function MainButton(linkProps: LinkProps): JSX.Element; +//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element; +//// let opt = ; +//// let opt = ; +//// let opt = {}} />; +//// let opt = {}} ignore-prop />; +//// let opt = ; +//// let opt = ; + + +let ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/tsxRename13.ts b/tests/cases/fourslash/tsxRename13.ts new file mode 100644 index 00000000000..02d0fb1b3dd --- /dev/null +++ b/tests/cases/fourslash/tsxRename13.ts @@ -0,0 +1,39 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// goTo: string; +//// } +//// declare function MainButton(buttonProps: ButtonProps): JSX.Element; +//// declare function MainButton(linkProps: LinkProps): JSX.Element; +//// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element; +//// let opt = ; +//// let opt = ; +//// let opt = {}} />; +//// let opt = {}} [|ignore-prop|] />; +//// let opt = ; +//// let opt = ; + + +let ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/tsxRename6.ts b/tests/cases/fourslash/tsxRename6.ts new file mode 100644 index 00000000000..59bc3f48009 --- /dev/null +++ b/tests/cases/fourslash/tsxRename6.ts @@ -0,0 +1,30 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface OptionPropBag { +//// propx: number +//// propString: string +//// optional?: boolean +//// } +//// declare function [|Opt|](attributes: OptionPropBag): JSX.Element; +//// let opt = <[|Opt|] />; +//// let opt1 = <[|Opt|] propx={100} propString />; +//// let opt2 = <[|Opt|] propx={100} optional/>; +//// let opt3 = <[|Opt|] wrong />; +//// let opt4 = <[|Opt|] propx={100} propString="hi" />; + +let ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/tsxRename7.ts b/tests/cases/fourslash/tsxRename7.ts new file mode 100644 index 00000000000..b5d05e49bd3 --- /dev/null +++ b/tests/cases/fourslash/tsxRename7.ts @@ -0,0 +1,29 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface OptionPropBag { +//// [|propx|]: number +//// propString: string +//// optional?: boolean +//// } +//// declare function Opt(attributes: OptionPropBag): JSX.Element; +//// let opt = ; +//// let opt1 = ; +//// let opt2 = ; +//// let opt3 = ; + +let ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/tsxRename8.ts b/tests/cases/fourslash/tsxRename8.ts new file mode 100644 index 00000000000..48bbff0d88e --- /dev/null +++ b/tests/cases/fourslash/tsxRename8.ts @@ -0,0 +1,31 @@ +/// +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface OptionPropBag { +//// propx: number +//// propString: string +//// optional?: boolean +//// } +//// declare function Opt(attributes: OptionPropBag): JSX.Element; +//// let opt = ; +//// let opt1 = ; +//// let opt2 = ; +//// let opt3 = ; +//// let opt4 = ; + +let ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/tsxRename9.ts b/tests/cases/fourslash/tsxRename9.ts new file mode 100644 index 00000000000..4d132f5eac9 --- /dev/null +++ b/tests/cases/fourslash/tsxRename9.ts @@ -0,0 +1,38 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } +//// interface ClickableProps { +//// children?: string; +//// className?: string; +//// } +//// interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } +//// interface LinkProps extends ClickableProps { +//// goTo: string; +//// } +//// declare function [|MainButton|](buttonProps: ButtonProps): JSX.Element; +//// declare function [|MainButton|](linkProps: LinkProps): JSX.Element; +//// declare function [|MainButton|](props: ButtonProps | LinkProps): JSX.Element; +//// let opt = <[|MainButton|] />; +//// let opt = <[|MainButton|] children="chidlren" />; +//// let opt = <[|MainButton|] onClick={()=>{}} />; +//// let opt = <[|MainButton|] onClick={()=>{}} ignore-prop />; +//// let opt = <[|MainButton|] goTo="goTo" />; +//// let opt = <[|MainButton|] wrong />; + +let ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/tsxSignatureHelp1.ts b/tests/cases/fourslash/tsxSignatureHelp1.ts new file mode 100644 index 00000000000..a0fd59d11ec --- /dev/null +++ b/tests/cases/fourslash/tsxSignatureHelp1.ts @@ -0,0 +1,35 @@ +/// + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +//// import React = require('react'); +//// export interface ClickableProps { +//// children?: string; +//// className?: string; +//// } + +//// export interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } + +//// function _buildMainButton({ onClick, children, className }: ButtonProps): JSX.Element { +//// return(); +//// } + +//// export function MainButton(props: ButtonProps): JSX.Element { +//// return this._buildMainButton(props); +//// } +//// let e1 = + +//@Filename: file.tsx +// @jsx: preserve +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +//// import React = require('react'); +//// export interface ClickableProps { +//// children?: string; +//// className?: string; +//// } + +//// export interface ButtonProps extends ClickableProps { +//// onClick(event?: React.MouseEvent): void; +//// } + +//// export interface LinkProps extends ClickableProps { +//// goTo(where: "home" | "contact"): void; +//// } + +//// function _buildMainButton({ onClick, children, className }: ButtonProps): JSX.Element { +//// return(); +//// } + +//// export function MainButton(buttonProps: ButtonProps): JSX.Element; +//// export function MainButton(linkProps: LinkProps): JSX.Element; +//// export function MainButton(props: ButtonProps | LinkProps): JSX.Element { +//// return this._buildMainButton(props); +//// } +//// let e1 =