forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneratedCodeSymbolsTests.fs
104 lines (90 loc) · 4.05 KB
/
GeneratedCodeSymbolsTests.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module FSharp.Compiler.Service.Tests.GeneratedCodeSymbolsTests
open Xunit
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Service.Tests.Common
open FSharp.Compiler.Symbols
[<Literal>]
let dirName = "GeneratedCodeSymbolsTests"
[<Fact>]
let ``IsUnionCaseTester for Is* member in a class`` () =
let source = """
module Lib
type T () =
member x.IsM = 1
"""
let cleanup, options = createProjectOptions dirName [ source ] [ "--langversion:preview" ]
use _holder = cleanup
let exprChecker = FSharpChecker.Create(keepAssemblyContents=true, useTransparentCompiler=false)
let wholeProjectResults = exprChecker.ParseAndCheckProject(options) |> Async.RunImmediate
let mfvs =
seq {
for implFile in wholeProjectResults.AssemblyContents.ImplementationFiles do
for decl in implFile.Declarations do
match decl with
| FSharpImplementationFileDeclaration.Entity(e,ds) ->
for d in ds do
match d with
| FSharpImplementationFileDeclaration.MemberOrFunctionOrValue (mfv, args, body) ->
yield mfv
| _ -> ()
| _ -> ()
}
Assert.Contains(mfvs, fun x -> x.LogicalName = "get_IsM")
let mfv = mfvs |> Seq.filter (fun x -> x.LogicalName = "get_IsM") |> Seq.exactlyOne
Assert.False(mfv.IsUnionCaseTester, $"get_IsM has IsUnionCaseTester = {mfv.IsUnionCaseTester}")
[<Fact>]
let ``IsUnionCaseTester for Is* generated property in DU`` () =
let source = """
module Lib
type T = A | B
"""
let cleanup, options = createProjectOptions dirName [ source ] [ "--langversion:preview" ]
use _holder = cleanup
let exprChecker = FSharpChecker.Create(keepAssemblyContents=true, useTransparentCompiler=false)
let wholeProjectResults = exprChecker.ParseAndCheckProject(options) |> Async.RunImmediate
let mfvs =
seq {
for implFile in wholeProjectResults.AssemblyContents.ImplementationFiles do
for decl in implFile.Declarations do
match decl with
| FSharpImplementationFileDeclaration.Entity(e,ds) ->
for d in ds do
match d with
| FSharpImplementationFileDeclaration.MemberOrFunctionOrValue (mfv, args, body) ->
yield mfv
| _ -> ()
| _ -> ()
}
Assert.Contains(mfvs, fun x -> x.LogicalName = "get_IsA")
let mfv = mfvs |> Seq.filter (fun x -> x.LogicalName = "get_IsA") |> Seq.exactlyOne
Assert.True(mfv.IsUnionCaseTester, $"get_IsA has IsUnionCaseTester = {mfv.IsUnionCaseTester}")
[<Fact>]
let ``IsUnionCaseTester for Is* user property in DU`` () =
let source = """
module Lib
type T =
| A
| B
member x.IsC
with get () = false
"""
let cleanup, options = createProjectOptions dirName [ source ] [ "--langversion:preview" ]
use _holder = cleanup
let exprChecker = FSharpChecker.Create(keepAssemblyContents=true, useTransparentCompiler=false)
let wholeProjectResults = exprChecker.ParseAndCheckProject(options) |> Async.RunImmediate
let mfvs =
seq {
for implFile in wholeProjectResults.AssemblyContents.ImplementationFiles do
for decl in implFile.Declarations do
match decl with
| FSharpImplementationFileDeclaration.Entity(e,ds) ->
for d in ds do
match d with
| FSharpImplementationFileDeclaration.MemberOrFunctionOrValue (mfv, args, body) ->
yield mfv
| _ -> ()
| _ -> ()
}
Assert.Contains(mfvs, fun x -> x.LogicalName = "get_IsC")
let mfv = mfvs |> Seq.filter (fun x -> x.LogicalName = "get_IsC") |> Seq.exactlyOne
Assert.False(mfv.IsUnionCaseTester, $"get_IsC has IsUnionCaseTester = {mfv.IsUnionCaseTester}")