|
| 1 | +package fourslash_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/microsoft/typescript-go/internal/fourslash" |
| 7 | + . "github.com/microsoft/typescript-go/internal/fourslash/tests/util" |
| 8 | + "github.com/microsoft/typescript-go/internal/lsp/lsproto" |
| 9 | + "github.com/microsoft/typescript-go/internal/testutil" |
| 10 | +) |
| 11 | + |
| 12 | +func TestCompletionInTernaryConditional(t *testing.T) { |
| 13 | + t.Parallel() |
| 14 | + |
| 15 | + defer testutil.RecoverAndFail(t, "Panic on fourslash test") |
| 16 | + const content = `export enum Bar { } |
| 17 | +export enum Foo { } |
| 18 | +
|
| 19 | +
|
| 20 | +function foo(x: Foo) { return x; } |
| 21 | +function bar(z: string, x: Foo) { return x; } |
| 22 | +
|
| 23 | +const a = ''; |
| 24 | +
|
| 25 | +foo(/*1*/); |
| 26 | +bar(a, a == '' ? /*2*/); |
| 27 | +bar(a, a == '' ? /*3*/ : /*4*/);` |
| 28 | + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) |
| 29 | + defer done() |
| 30 | + |
| 31 | + // Test marker 1 - should have Foo preselected in simple call |
| 32 | + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ |
| 33 | + IsIncomplete: false, |
| 34 | + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ |
| 35 | + CommitCharacters: &DefaultCommitCharacters, |
| 36 | + EditRange: Ignored, |
| 37 | + }, |
| 38 | + Items: &fourslash.CompletionsExpectedItems{ |
| 39 | + Includes: []fourslash.CompletionsExpectedItem{ |
| 40 | + &lsproto.CompletionItem{ |
| 41 | + Label: "Foo", |
| 42 | + Kind: PtrTo(lsproto.CompletionItemKindEnum), |
| 43 | + Preselect: PtrTo(true), |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }) |
| 48 | + |
| 49 | + // Test marker 2 - should have Foo preselected after ? in incomplete ternary |
| 50 | + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ |
| 51 | + IsIncomplete: false, |
| 52 | + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ |
| 53 | + CommitCharacters: &DefaultCommitCharacters, |
| 54 | + EditRange: Ignored, |
| 55 | + }, |
| 56 | + Items: &fourslash.CompletionsExpectedItems{ |
| 57 | + Includes: []fourslash.CompletionsExpectedItem{ |
| 58 | + &lsproto.CompletionItem{ |
| 59 | + Label: "Foo", |
| 60 | + Kind: PtrTo(lsproto.CompletionItemKindEnum), |
| 61 | + Preselect: PtrTo(true), |
| 62 | + }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + }) |
| 66 | + |
| 67 | + // Test marker 3 - should have Foo preselected after ? in ternary with colon |
| 68 | + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ |
| 69 | + IsIncomplete: false, |
| 70 | + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ |
| 71 | + CommitCharacters: &DefaultCommitCharacters, |
| 72 | + EditRange: Ignored, |
| 73 | + }, |
| 74 | + Items: &fourslash.CompletionsExpectedItems{ |
| 75 | + Includes: []fourslash.CompletionsExpectedItem{ |
| 76 | + &lsproto.CompletionItem{ |
| 77 | + Label: "Foo", |
| 78 | + Kind: PtrTo(lsproto.CompletionItemKindEnum), |
| 79 | + Preselect: PtrTo(true), |
| 80 | + }, |
| 81 | + }, |
| 82 | + }, |
| 83 | + }) |
| 84 | + |
| 85 | + // Test marker 4 - should have Foo preselected after : in ternary |
| 86 | + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ |
| 87 | + IsIncomplete: false, |
| 88 | + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ |
| 89 | + CommitCharacters: &DefaultCommitCharacters, |
| 90 | + EditRange: Ignored, |
| 91 | + }, |
| 92 | + Items: &fourslash.CompletionsExpectedItems{ |
| 93 | + Includes: []fourslash.CompletionsExpectedItem{ |
| 94 | + &lsproto.CompletionItem{ |
| 95 | + Label: "Foo", |
| 96 | + Kind: PtrTo(lsproto.CompletionItemKindEnum), |
| 97 | + Preselect: PtrTo(true), |
| 98 | + }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + }) |
| 102 | +} |
0 commit comments