@@ -36,145 +36,127 @@ open System.Runtime.InteropServices
3636[<InlineData( " : int" ) >]
3737[<InlineData( " : int" ) >]
3838let ``Refactor should not trigger`` ( shouldNotTrigger : string ) =
39- task {
40- let symbolName = " sum"
39+ let symbolName = " sum"
4140
42- let code =
43- $"""
41+ let code =
42+ $"""
4443 let sum a b {shouldNotTrigger}= a + b
4544 """
4645
47- use context = TestContext.CreateWithCode code
46+ use context = TestContext.CreateWithCode code
4847
49- let spanStart = code.IndexOf symbolName
48+ let spanStart = code.IndexOf symbolName
5049
51- let! actions = tryGetRefactoringActions code spanStart context ( new AddExplicitReturnType())
50+ let actions =
51+ tryGetRefactoringActions code spanStart context ( new AddExplicitReturnType())
5252
53- do Assert.Empty( actions)
54- }
53+ do Assert.Empty( actions)
5554
5655[<Fact>]
5756let ``Correctly infer int as explicit return type`` () =
58- task {
57+ let symbolName = " sum "
5958
60- let symbolName = " sum"
59+ let code =
60+ """
61+ let sum a b = a + b
62+ """
6163
62- let code =
63- """
64- let sum a b = a + b
65- """
64+ use context = TestContext.CreateWithCode code
6665
67- use context = TestContext.CreateWithCode code
66+ let spanStart = code.IndexOf symbolName
6867
69- let spanStart = code.IndexOf symbolName
68+ let newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType ())
7069
71- let! newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType())
72-
73- do ! AssertHasSpecificExplicitReturnType symbolName " int" newDoc context.CT
74- }
70+ AssertHasSpecificExplicitReturnType symbolName " int" newDoc context.CT
7571
7672[<Theory>]
7773[<InlineData( " (a:float) (b:int)" , " float" ) >]
7874[<InlineData( " a:int b:int" , " int" ) >]
7975let ``Infer explicit return type`` ( functionHeader : string ) ( returnType : string ) =
80- task {
76+ let symbolName = " sum "
8177
82- let symbolName = " sum"
78+ let code =
79+ $"""
80+ let sum {functionHeader}= a + b
81+ """
8382
84- let code =
85- $"""
86- let sum {functionHeader}= a + b
87- """
83+ use context = TestContext.CreateWithCode code
8884
89- use context = TestContext.CreateWithCode code
85+ let spanStart = code.IndexOf ( symbolName )
9086
91- let spanStart = code.IndexOf( symbolName)
87+ let newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType())
88+ let text = newDoc.GetTextAsync() |> GetTaskResult
9289
93- let! newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType())
94-
95- do ! AssertHasSpecificExplicitReturnType symbolName returnType newDoc context.CT
96- }
90+ AssertHasSpecificExplicitReturnType symbolName returnType newDoc context.CT
9791
9892[<Fact>]
9993let ``Infer on rec method`` () =
100- task {
101-
102- let symbolName = " fib"
94+ let symbolName = " fib"
10395
104- let code =
105- $"""
106- let rec fib n =
107- if n < 2 then 1 else fib (n - 1) + fib (n - 2)
108- """
96+ let code =
97+ $"""
98+ let rec fib n =
99+ if n < 2 then 1 else fib (n - 1) + fib (n - 2)
100+ """
109101
110- use context = TestContext.CreateWithCode code
102+ use context = TestContext.CreateWithCode code
111103
112- let spanStart = code.IndexOf symbolName
104+ let spanStart = code.IndexOf symbolName
113105
114- let! newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType())
106+ let newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType())
115107
116- do ! AssertHasSpecificExplicitReturnType symbolName " int" newDoc context.CT
117- }
108+ AssertHasSpecificExplicitReturnType symbolName " int" newDoc context.CT
118109
119110[<Fact>]
120111let ``Infer with function parameter method`` () =
121- task {
112+ let symbolName = " apply1 "
122113
123- let symbolName = " apply1"
114+ let code =
115+ $"""
116+ let apply1 (transform: int -> int) y = transform y
117+ """
124118
125- let code =
126- $"""
127- let apply1 (transform: int -> int) y = transform y
128- """
129-
130- use context = TestContext.CreateWithCode code
119+ use context = TestContext.CreateWithCode code
131120
132- let spanStart = code.IndexOf symbolName
121+ let spanStart = code.IndexOf symbolName
133122
134- let! newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType())
123+ let newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType())
135124
136- do ! AssertHasSpecificExplicitReturnType symbolName " int" newDoc context.CT
137- }
125+ AssertHasSpecificExplicitReturnType symbolName " int" newDoc context.CT
138126
139127[<Fact>]
140128let ``Infer on member function`` () =
141- task {
129+ let symbolName = " SomeMethod "
142130
143- let symbolName = " SomeMethod"
144-
145- let code =
146- $"""
147- type SomeType(factor0: int) =
148- let factor = factor0
149- member this.SomeMethod(a, b, c) = (a + b + c) * factor
150- """
131+ let code =
132+ $"""
133+ type SomeType(factor0: int) =
134+ let factor = factor0
135+ member this.SomeMethod(a, b, c) = (a + b + c) * factor
136+ """
151137
152- use context = TestContext.CreateWithCode code
138+ use context = TestContext.CreateWithCode code
153139
154- let spanStart = code.IndexOf symbolName
140+ let spanStart = code.IndexOf symbolName
155141
156- let! newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType())
142+ let newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType())
157143
158- do ! AssertHasSpecificExplicitReturnType symbolName " int" newDoc context.CT
159- }
144+ AssertHasSpecificExplicitReturnType symbolName " int" newDoc context.CT
160145
161146[<Fact>]
162147let ``Correctly infer custom type that is declared earlier in file`` () =
163- task {
164- let symbolName = " sum"
165-
166- let code =
167- """
168- type MyType = { Value: int }
169- let sum a b = {Value=a+b}
170- """
148+ let symbolName = " sum"
171149
172- use context = TestContext.CreateWithCode code
150+ let code =
151+ """
152+ type MyType = { Value: int }
153+ let sum a b = {Value=a+b}
154+ """
173155
174- let spanStart = code.IndexOf symbolName
156+ use context = TestContext.CreateWithCode code
175157
176- let! newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType ())
158+ let spanStart = code.IndexOf symbolName
177159
178- do ! AssertHasSpecificExplicitReturnType symbolName " MyType " newDoc context.CT
160+ let newDoc = tryRefactor code spanStart context ( new AddExplicitReturnType ())
179161
180- }
162+ AssertHasSpecificExplicitReturnType symbolName " MyType " newDoc context.CT
0 commit comments