Skip to content

Commit e08e9fa

Browse files
* feat(FSharp.Editor.Tests): add AsyncBugReproduction.fs to test suite
* fix(AddExplicitReturnType.fs): remove unnecessary assertion * fix(RefactorTestFramework.fs): convert symbols sequence to list
1 parent 1409f3a commit e08e9fa

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<Compile Include="Refactors\RefactorTestFramework.fs" />
7474
<Compile Include="Refactors\AddExplicitReturnType.fs" />
7575
<Compile Include="Refactors\RemoveExplicitReturnType.fs" />
76+
<Compile Include="Refactors\AsyncBugReproduction.fs" />
7677
<Compile Include="Hints\HintTestFramework.fs" />
7778
<Compile Include="Hints\OptionParserTests.fs" />
7879
<Compile Include="Hints\InlineParameterNameHintTests.fs" />

vsintegration/tests/FSharp.Editor.Tests/Refactors/AddExplicitReturnType.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ let ``Infer explicit return type`` (functionHeader: string) (returnType: string)
9191
let spanStart = code.IndexOf(symbolName)
9292

9393
let! newDoc = tryRefactor code spanStart context (new AddExplicitReturnType())
94-
do Assert.NotNull(code)
94+
9595
do! AssertHasSpecificExplicitReturnType symbolName returnType newDoc context.CT
9696
}
9797

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
module FSharp.Editor.Tests.Refactors.AsyncBugReproduction
2+
3+
open Microsoft.VisualStudio.FSharp.Editor
4+
open Xunit
5+
open System
6+
open System.Collections.Immutable
7+
open System.Text.RegularExpressions
8+
9+
open Microsoft.CodeAnalysis
10+
open Microsoft.CodeAnalysis.CodeFixes
11+
open Microsoft.CodeAnalysis.Text
12+
open Microsoft.VisualStudio.FSharp.Editor
13+
open Microsoft.VisualStudio.FSharp.Editor.CancellableTasks
14+
15+
open FSharp.Compiler.Diagnostics
16+
open FSharp.Editor.Tests.Helpers
17+
18+
open Microsoft.CodeAnalysis.CodeRefactorings
19+
open NUnit.Framework
20+
open Microsoft.CodeAnalysis.CodeActions
21+
open System.Collections.Generic
22+
open Microsoft.VisualStudio.LanguageServices
23+
open FSharp.Editor.Tests.Refactors.RefactorTestFramework
24+
open Microsoft.Build.Utilities
25+
open System.Threading
26+
open FSharp.Test.ReflectionHelper
27+
open Microsoft.Build.Utilities
28+
open FSharp.Test.ProjectGeneration.ProjectOperations
29+
open FSharp.Compiler.Symbols
30+
open Xunit
31+
open System.Runtime.InteropServices
32+
33+
[<Theory>]
34+
[<InlineData("(a:float) (b:int)", "float")>]
35+
[<InlineData("(a:float) (b:int)", "float")>]
36+
let ``Reproducing code null spanStart Bug`` (functionHeader: string) (returnType: string) =
37+
task {
38+
39+
let symbolName = "sum"
40+
41+
let code =
42+
$"""
43+
let sum {functionHeader}= a + b
44+
"""
45+
46+
use context = TestContext.CreateWithCode code
47+
48+
let spanStart = code.IndexOf(symbolName)
49+
50+
let! newDoc = tryRefactor code spanStart context (new AddExplicitReturnType())
51+
52+
do! AssertHasSpecificExplicitReturnType symbolName returnType newDoc context.CT
53+
}
54+
55+
[<Theory>]
56+
[<InlineData("(a:float) (b:int)", "float")>]
57+
[<InlineData("(a:float) (b:int)", "float")>]
58+
let ``But works when not async`` (functionHeader: string) (returnType: string) =
59+
60+
let symbolName = "sum"
61+
62+
let code =
63+
$"""
64+
let sum {functionHeader}= a + b
65+
"""
66+
67+
use context = TestContext.CreateWithCode code
68+
69+
let spanStart = code.IndexOf(symbolName)
70+
71+
let newDocTask = tryRefactor code spanStart context (new AddExplicitReturnType())
72+
let newDoc = newDocTask.GetAwaiter().GetResult()
73+
74+
let assertTask =
75+
AssertHasSpecificExplicitReturnType symbolName returnType newDoc context.CT
76+
77+
do assertTask.GetAwaiter().GetResult()

vsintegration/tests/FSharp.Editor.Tests/Refactors/RefactorTestFramework.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ let GetReturnTypeOfSymbol (symbolName: string) (document: Document) ct =
4747
document.GetFSharpParseAndCheckResultsAsync symbolName
4848
|> CancellableTask.start ct
4949

50-
let symbols = checkFileResults.GetAllUsesOfAllSymbolsInFile ct
50+
let symbols = checkFileResults.GetAllUsesOfAllSymbolsInFile ct |> List.ofSeq
5151
let symbolUse = symbols |> Seq.find (fun s -> s.Symbol.DisplayName = symbolName)
5252

5353
return

0 commit comments

Comments
 (0)