forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguageDebugInfoServiceTests.fs
75 lines (59 loc) · 2.55 KB
/
LanguageDebugInfoServiceTests.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
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.Editor.Tests
open System
open System.Threading
open Xunit
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis
open Microsoft.VisualStudio.FSharp.Editor
open FSharp.Compiler.Text
type LanguageDebugInfoServiceTests() =
let fileName = "C:\\test.fs"
let defines = []
let code =
"
// This is a comment
[<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 \"%d\" objectValue.exampleMember
0 // return an integer exit code
"
static member testCases: Object[][] =
[|
[| "123456"; None |] // Numeric literals are not interesting
[| "is a string"; Some("\"This is a string\"") |]
[| "objectValue"; Some("objectValue") |]
[| "exampleMember"; Some("objectValue.exampleMember") |]
[| "%s"; Some("\"%d %s %A\"") |]
|]
[<Theory>]
[<MemberData(nameof (LanguageDebugInfoServiceTests.testCases))>]
member this.TestDebugInfo(searchToken: string, expectedDataTip: string option) =
let searchPosition = code.IndexOf(searchToken)
Assert.True(searchPosition >= 0, $"SearchToken '{searchToken}' is not found in code")
let sourceText = SourceText.From(code)
let documentId = DocumentId.CreateNewId(ProjectId.CreateNewId())
let classifiedSpans =
Tokenizer.getClassifiedSpans (
documentId,
sourceText,
TextSpan.FromBounds(0, sourceText.Length),
Some(fileName),
defines,
CancellationToken.None
)
let actualDataTipSpanOption =
FSharpLanguageDebugInfoService.GetDataTipInformation(sourceText, searchPosition, classifiedSpans)
match actualDataTipSpanOption with
| None -> Assert.True(expectedDataTip.IsNone, "LanguageDebugInfoService failed to produce a data tip")
| Some (actualDataTipSpan) ->
let actualDataTipText = sourceText.GetSubText(actualDataTipSpan).ToString()
Assert.True(expectedDataTip.IsSome, $"LanguageDebugInfoService produced a data tip while it shouldn't at: {actualDataTipText}")
Assert.Equal(expectedDataTip.Value, actualDataTipText)