forked from fsprojects/fantomas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterfaceStaticMethodTests.fs
156 lines (112 loc) · 5.29 KB
/
InterfaceStaticMethodTests.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
module Fantomas.Core.Tests.InterfaceStaticMethodTests
open NUnit.Framework
open FsUnit
open Fantomas.Core.Tests.TestHelper
[<Test>]
let ``static member in constraint`` () =
formatSourceString
false
"""
// Check that "property" and "get_ method" constraints are considered logically equivalent
let inline f_StaticProperty<'T when 'T : (static member StaticProperty: int) >() : int = 'T.StaticProperty
let inline f_StaticMethod<'T when 'T : (static member StaticMethod: int -> int) >() : int = 'T.StaticMethod(3)
let inline f_set_StaticProperty<'T when 'T : (static member StaticProperty: int with set) >() = 'T.set_StaticProperty(3)
let inline f_InstanceMethod<'T when 'T : (member InstanceMethod: int -> int) >(x: 'T) : int = x.InstanceMethod(3)
let inline f_Length<'T when 'T : (member Length: int) >(x: 'T) = x.Length
let inline f_set_Length<'T when 'T : (member Length: int with set) >(x: 'T) = x.set_Length(3)
let inline f_Item<'T when 'T : (member Item: int -> string with get) >(x: 'T) = x.get_Item(3)
"""
config
|> prepend newline
|> should
equal
"""
// Check that "property" and "get_ method" constraints are considered logically equivalent
let inline f_StaticProperty<'T when 'T: (static member StaticProperty: int)> () : int = 'T.StaticProperty
let inline f_StaticMethod<'T when 'T: (static member StaticMethod: int -> int)> () : int = 'T.StaticMethod(3)
let inline f_set_StaticProperty<'T when 'T: (static member StaticProperty: int with set)> () = 'T.set_StaticProperty (3)
let inline f_InstanceMethod<'T when 'T: (member InstanceMethod: int -> int)> (x: 'T) : int = x.InstanceMethod(3)
let inline f_Length<'T when 'T: (member Length: int)> (x: 'T) = x.Length
let inline f_set_Length<'T when 'T: (member Length: int with set)> (x: 'T) = x.set_Length (3)
let inline f_Item<'T when 'T: (member Item: int -> string with get)> (x: 'T) = x.get_Item (3)
"""
[<Test>]
let ``self constrained type parameter`` () =
formatSourceString
false
"""
open System
open Types
module CheckSelfConstrainedIWSAM =
let f_IWSAM_explicit_operator_name<'T when IAdditionOperator<'T>>(x: 'T, y: 'T) =
'T.op_Addition(x, y)
let f_IWSAM_pretty_operator_name<'T when IAdditionOperator<'T>>(x: 'T, y: 'T) =
'T.(+)(x, y)
let f_IWSAM_StaticProperty<'T when IStaticProperty<'T>>() =
'T.StaticProperty
let f_IWSAM_declared_StaticMethod<'T when IStaticMethod<'T>>(x: 'T) =
'T.StaticMethod(x)
let f_IWSAM_declared_UnitMethod<'T when IUnitMethod<'T>>() =
'T.UnitMethod()
let f_IWSAM_declared_UnitMethod_list<'T when IUnitMethod<'T>>() =
let v = 'T.UnitMethod()
[ v ]
let inline f3<'T when IAdditionOperator<'T>>(x: 'T, y: 'T) =
'T.op_Addition(x,y)
type WithStaticProperty<'T when 'T : (static member StaticProperty: int)> = 'T
type WithStaticMethod<'T when 'T : (static member StaticMethod: int -> int)> = 'T
type WithBoth<'T when WithStaticProperty<'T> and WithStaticMethod<'T>> = 'T
let inline f_StaticProperty<'T when WithStaticProperty<'T>>() = 'T.StaticProperty
let inline f_StaticMethod<'T when WithStaticMethod<'T>>() = 'T.StaticMethod(3)
let inline f_Both<'T when WithBoth<'T> >() =
let v1 = 'T.StaticProperty
let v2 = 'T.StaticMethod(3)
v1 + v2
let inline f_OK1<'T when WithBoth<'T>>() =
'T.StaticMethod(3) |> ignore
'T.StaticMethod(3)
let inline f_OK2<'T when WithBoth<'T>>() =
'T.StaticMethod(3) |> ignore
'T.StaticMethod(3)
let inline f_OK3<'T when WithBoth<'T>>() =
printfn ""
'T.StaticMethod(3)
printfn ""
"""
config
|> prepend newline
|> should
equal
"""
open System
open Types
module CheckSelfConstrainedIWSAM =
let f_IWSAM_explicit_operator_name<'T when IAdditionOperator<'T>> (x: 'T, y: 'T) = 'T.op_Addition (x, y)
let f_IWSAM_pretty_operator_name<'T when IAdditionOperator<'T>> (x: 'T, y: 'T) = 'T.(+) (x, y)
let f_IWSAM_StaticProperty<'T when IStaticProperty<'T>> () = 'T.StaticProperty
let f_IWSAM_declared_StaticMethod<'T when IStaticMethod<'T>> (x: 'T) = 'T.StaticMethod(x)
let f_IWSAM_declared_UnitMethod<'T when IUnitMethod<'T>> () = 'T.UnitMethod()
let f_IWSAM_declared_UnitMethod_list<'T when IUnitMethod<'T>> () =
let v = 'T.UnitMethod()
[ v ]
let inline f3<'T when IAdditionOperator<'T>> (x: 'T, y: 'T) = 'T.op_Addition (x, y)
type WithStaticProperty<'T when 'T: (static member StaticProperty: int)> = 'T
type WithStaticMethod<'T when 'T: (static member StaticMethod: int -> int)> = 'T
type WithBoth<'T when WithStaticProperty<'T> and WithStaticMethod<'T>> = 'T
let inline f_StaticProperty<'T when WithStaticProperty<'T>> () = 'T.StaticProperty
let inline f_StaticMethod<'T when WithStaticMethod<'T>> () = 'T.StaticMethod(3)
let inline f_Both<'T when WithBoth<'T>> () =
let v1 = 'T.StaticProperty
let v2 = 'T.StaticMethod(3)
v1 + v2
let inline f_OK1<'T when WithBoth<'T>> () =
'T.StaticMethod(3) |> ignore
'T.StaticMethod(3)
let inline f_OK2<'T when WithBoth<'T>> () =
'T.StaticMethod(3) |> ignore
'T.StaticMethod(3)
let inline f_OK3<'T when WithBoth<'T>> () =
printfn ""
'T.StaticMethod(3)
printfn ""
"""