forked from fsprojects/fantomas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttributeTests.fs
123 lines (107 loc) · 2.65 KB
/
AttributeTests.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
module Fantomas.Tests.AttributeTests
open NUnit.Framework
open FsUnit
open Fantomas.CodeFormatter
open Fantomas.Tests.TestHelper
[<Test>]
let ``should keep the attribute on top of the function``() =
formatSourceString false """[<Extension>]
type Funcs =
[<Extension>]
static member ToFunc (f: Action<_,_,_>) =
Func<_,_,_,_>(fun a b c -> f.Invoke(a,b,c))
""" config
|> should equal """[<Extension>]
type Funcs =
[<Extension>]
static member ToFunc(f : Action<_, _, _>) =
Func<_, _, _, _>(fun a b c -> f.Invoke(a, b, c))
"""
[<Test>]
let ``attributes on expressions``() =
formatSourceString false """
[<Dependency("FSharp.Compiler", LoadHint.Always)>]
do ()""" config
|> prepend newline
|> should equal """
[<Dependency("FSharp.Compiler", LoadHint.Always)>]
do ()
"""
[<Test>]
let ``units of measures declaration``() =
formatSourceString false """
[<Measure>] type m
[<Measure>] type kg
[<Measure>] type s
[<Measure>] type N = kg m / s^2
[<Measure>] type Pa = N * m^2""" config
|> prepend newline
|> should equal """
[<Measure>]
type m
[<Measure>]
type kg
[<Measure>]
type s
[<Measure>]
type N = kg m / s^2
[<Measure>]
type Pa = N * m^2
"""
[<Test>]
let ``type params``() =
formatSourceString false """
let genericSumUnits ( x : float<'u>) (y: float<'u>) = x + y
type vector3D<[<Measure>] 'u> = { x : float<'u>; y : float<'u>; z : float<'u>}""" config
|> prepend newline
|> should equal """
let genericSumUnits (x : float<'u>) (y : float<'u>) = x + y
type vector3D<[<Measure>] 'u> =
{ x : float<'u>
y : float<'u>
z : float<'u> }
"""
[<Test>]
let ``attributes on recursive functions``() =
formatSourceString false """
let rec [<Test>] a () = 10
and [<Test>] b () = 10""" config
|> prepend newline
|> should equal """
[<Test>]
let rec a() = 10
and [<Test>] b() = 10
"""
[<Test>]
let ``attributes on implicit constructors``() =
formatSourceString false """
[<Export>]
type Sample [<ImportingConstructor>] (dependency: IDependency) = class end
[<Export>]
type Sample [<ImportingConstructor>] internal () = class end""" config
|> prepend newline
|> should equal """
[<Export>]
type Sample [<ImportingConstructor>] (dependency : IDependency) =
class
end
[<Export>]
type Sample [<ImportingConstructor>] internal () =
class
end
"""
[<Test>]
let ``should handle targets on attributes``() =
formatSourceString false """
[<DataContract>]
type Foo =
{ [<field:DataMember>]
Bar:string }
""" config
|> prepend newline
|> should equal """
[<DataContract>]
type Foo =
{ [<field:DataMember>]
Bar : string }
"""