-
Notifications
You must be signed in to change notification settings - Fork 867
Expand file tree
/
Copy pathCompletionTests.fs
More file actions
169 lines (147 loc) · 8.33 KB
/
Copy pathCompletionTests.fs
File metadata and controls
169 lines (147 loc) · 8.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.Compiler.Scripting.UnitTests
open System
open System.Threading.Tasks
open FSharp.Test.ScriptHelpers
open Xunit
type CompletionTests() =
[<Fact>]
member _.``Instance completions in the same submission``() =
async {
use script = new FSharpScript()
let lines = [ "let x = 1"
"x." ]
let! completions = script.GetCompletionItems(String.Join("\n", lines), 2, 2)
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "CompareTo")
Assert.Equal(1, matchingCompletions.Length)
} |> Async.StartAsTask :> Task
[<Fact>]
member _.``Instance completions from a previous submission``() =
async {
use script = new FSharpScript()
script.Eval("let x = 1") |> ignoreValue
let! completions = script.GetCompletionItems("x.", 1, 2)
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "CompareTo")
Assert.Equal(1, matchingCompletions.Length)
} |> Async.StartAsTask :> Task
[<Fact>]
member _.``Completions from types that try to pull in Windows runtime extensions``() =
async {
use script = new FSharpScript()
script.Eval("open System") |> ignoreValue
script.Eval("let t = TimeSpan.FromHours(1.0)") |> ignoreValue
let! completions = script.GetCompletionItems("t.", 1, 2)
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "TotalHours")
Assert.Equal(1, matchingCompletions.Length)
} |> Async.StartAsTask :> Task
[<Fact>]
member _.``Static member completions``() =
async {
use script = new FSharpScript()
let! completions = script.GetCompletionItems("System.String.", 1, 14)
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "Join")
Assert.True(matchingCompletions.Length >= 1)
} |> Async.StartAsTask :> Task
[<Fact>]
member _.``Type completions from namespace``() =
async {
use script = new FSharpScript()
let! completions = script.GetCompletionItems("System.", 1, 7)
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "String")
Assert.True(matchingCompletions.Length >= 1)
} |> Async.StartAsTask :> Task
[<Fact>]
member _.``Namespace completions``() =
async {
use script = new FSharpScript()
let! completions = script.GetCompletionItems("System.", 1, 7)
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "Collections")
Assert.Equal(1, matchingCompletions.Length)
} |> Async.StartAsTask :> Task
[<Fact>]
member _.``Extension method completions``() =
async {
use script = new FSharpScript()
let lines = [ "open System.Linq"
"let list = new System.Collections.Generic.List<int>()"
"list." ]
let! completions = script.GetCompletionItems(String.Join("\n", lines), 3, 5)
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "Select")
Assert.Equal(1, matchingCompletions.Length)
} |> Async.StartAsTask :> Task
[<Fact>]
member _.``Completions with strange names for static members``() =
use script = new FSharpScript()
let lines = [ "type C() ="
" static member ``Long Name`` = 1"
" static member ``-``(a:C, b:C) = C()"
" static member op_Addition(a:C, b:C) = C()"
" static member ``base``(a:C, b:C) = C()"
" static member ``|A|_|``(a:C, b:C) = C()"
"C." ]
let completions = script.GetCompletionItems(String.Join("\n", lines), 7, 2) |> Async.RunSynchronously
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "Long Name")
Assert.Equal(1, matchingCompletions.Length)
Assert.Equal("``Long Name``", matchingCompletions.[0].NameInCode)
// Things with names like op_Addition are suppressed from completion by FCS
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "+")
Assert.Equal(0, matchingCompletions.Length)
// Strange names like ``+`` and ``-`` are just normal text and not operators
// and are present in completion lists
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "-")
Assert.Equal(1, matchingCompletions.Length)
Assert.Equal("``-``", matchingCompletions.[0].NameInCode)
// ``base`` is a strange name but is still present. In this case the inserted
// text NameInCode is ``base`` because the thing is not a base value mapping to
// the base keyword
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "base")
Assert.Equal(1, matchingCompletions.Length)
Assert.Equal("``base``", matchingCompletions.[0].NameInCode)
// ``|A|_|`` is a strange name like the name of an active pattern but is still present.
// In this case the inserted is (|A|_|)
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "|A|_|")
Assert.Equal(1, matchingCompletions.Length)
Assert.Equal("(|A|_|)", matchingCompletions.[0].NameInCode)
[<Fact>]
member _.``Completions with strange names for module``() =
use script = new FSharpScript()
let lines = [ "module M ="
" let ``Long Name`` = 1"
" let ``-``(a:int, b:int) = 1"
" let op_Addition(a:int, b:int) = 1"
" let ``base``(a:int, b:int) = 1"
" let (|A|_|)(a:int, b:int) = None"
"M." ]
let completions = script.GetCompletionItems(String.Join("\n", lines), 7, 2) |> Async.RunSynchronously
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "Long Name")
Assert.Equal(1, matchingCompletions.Length)
Assert.Equal("``Long Name``", matchingCompletions.[0].NameInCode)
// Things with names like op_Addition are suppressed from completion by FCS
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "+")
Assert.Equal(0, matchingCompletions.Length)
// Strange names like ``+`` and ``-`` are just normal text and not operators
// and are present in completion lists
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "-")
Assert.Equal(1, matchingCompletions.Length)
Assert.Equal("``-``", matchingCompletions.[0].NameInCode)
// ``base`` is a strange name but is still present. In this case the inserted
// text NameInCode is ``base`` because the thing is not a base value mapping to
// the base keyword
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "base")
Assert.Equal(1, matchingCompletions.Length)
Assert.Equal("``base``", matchingCompletions.[0].NameInCode)
// (|A|_|) is an active pattern and the completion item is the
// active pattern case A. In this case the inserted is A
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "A")
Assert.Equal(1, matchingCompletions.Length)
Assert.Equal("A", matchingCompletions.[0].NameInCode)
[<Fact>]
member _.``Completions for record field with backticks`` () =
use script = new FSharpScript()
let lines = [ "type MyRec = { ``field.field`` : string }"
"let a = {``field.field`` = \"\"}"
"a." ]
let completions = script.GetCompletionItems(String.Join("\n", lines), 3, 2) |> Async.RunSynchronously
let matchingCompletions = completions |> Array.filter (fun d -> d.NameInList = "field.field")
Assert.Equal(1, matchingCompletions.Length)
Assert.Equal("``field.field``", matchingCompletions.[0].NameInCode)