forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBreakpointResolutionServiceTests.fs
78 lines (60 loc) · 2.68 KB
/
BreakpointResolutionServiceTests.fs
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
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.Editor.Tests
open System
open Xunit
open Microsoft.CodeAnalysis.Text
open Microsoft.VisualStudio.FSharp.Editor
open FSharp.Editor.Tests.Helpers
type BreakpointResolutionServiceTests() =
let code =
"
// This is a comment
type exampleType(parameter: int) =
member this.exampleMember = parameter
[<EntryPoint>]
let main argv =
let integerValue = 123456
let stringValue = \"This is a string\"
let objectValue = exampleType(789)
printfn \"%d %s %A\" integerValue stringValue objectValue
let booleanValue = true
match booleanValue with
| true -> printfn \"correct\"
| false -> printfn \"wrong\"
0 // return an integer exit code
"
static member testCases: Object[][] =
[|
[| "This is a comment"; None |]
[| "123456"; Some("let integerValue = 123456") |]
[| "stringValue"; Some("let stringValue = \"This is a string\"") |]
[| "789"; Some("let objectValue = exampleType(789)") |]
[| "correct"; Some("printfn \"correct\"") |]
[| "wrong"; Some("printfn \"wrong\"") |]
[| "0"; Some("0") |]
|]
[<Theory>]
[<MemberData(nameof (BreakpointResolutionServiceTests.testCases))>]
member this.TestBreakpointResolution(searchToken: string, expectedResolution: string option) =
let searchPosition = code.IndexOf(searchToken)
Assert.True(searchPosition >= 0, $"SearchToken '{searchToken}' is not found in code")
let sourceText = SourceText.From(code)
let document =
RoslynTestHelpers.CreateSolution(code) |> RoslynTestHelpers.GetSingleDocument
let searchSpan =
TextSpan.FromBounds(searchPosition, searchPosition + searchToken.Length)
let actualResolutionOption =
FSharpBreakpointResolutionService.GetBreakpointLocation(document, searchSpan)
|> Async.RunSynchronously
match actualResolutionOption with
| None -> Assert.True(expectedResolution.IsNone, "BreakpointResolutionService failed to resolve breakpoint position")
| Some (actualResolutionRange) ->
let actualResolution =
sourceText
.GetSubText(RoslynHelpers.FSharpRangeToTextSpan(sourceText, actualResolutionRange))
.ToString()
Assert.True(
expectedResolution.IsSome,
$"BreakpointResolutionService resolved a breakpoint while it shouldn't at: {actualResolution}"
)
Assert.Equal(expectedResolution.Value, actualResolution)