forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSymbols.fs
More file actions
57 lines (45 loc) · 1.84 KB
/
Copy pathSymbols.fs
File metadata and controls
57 lines (45 loc) · 1.84 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
#if INTERACTIVE
#r "../../Debug/fcs/net45/FSharp.Compiler.Service.dll" // note, run 'build fcs debug' to generate this, this DLL has a public API so can be used from F# Interactive
#r "../../packages/NUnit.3.5.0/lib/net45/nunit.framework.dll"
#load "FsUnit.fs"
#load "Common.fs"
#else
module Tests.Service.Symbols
#endif
open FSharp.Compiler.Service.Tests.Common
open FsUnit
open NUnit.Framework
open Microsoft.FSharp.Compiler.SourceCodeServices
module ActivePatterns =
let completePatternInput = """
let (|True|False|) = function
| true -> True
| false -> False
match true with
| True | False -> ()
"""
let partialPatternInput = """
let (|String|_|) = function
| :? String -> Some ()
| _ -> None
match "foo" with
| String
| _ -> ()
"""
let getCaseUsages source line =
let fileName, options = mkTestFileAndOptions source [| |]
let _, checkResults = parseAndCheckFile fileName source options
checkResults.GetAllUsesOfAllSymbolsInFile()
|> Async.RunSynchronously
|> Array.filter (fun su -> su.RangeAlternate.StartLine = line && su.Symbol :? FSharpActivePatternCase)
|> Array.map (fun su -> su.Symbol :?> FSharpActivePatternCase)
[<Test>]
let ``Active pattern case indices`` () =
let getIndices = Array.map (fun (case: FSharpActivePatternCase) -> case.Index)
getCaseUsages completePatternInput 7 |> getIndices |> shouldEqual [| 0; 1 |]
getCaseUsages partialPatternInput 7 |> getIndices |> shouldEqual [| 0 |]
[<Test>]
let ``Active pattern group names`` () =
let getGroupName (case: FSharpActivePatternCase) = case.Group.Name.Value
getCaseUsages completePatternInput 7 |> Array.head |> getGroupName |> shouldEqual "|True|False|"
getCaseUsages partialPatternInput 7 |> Array.head |> getGroupName |> shouldEqual "|String|_|"