forked from fsprojects/fantomas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignatureTests.fs
138 lines (116 loc) · 4.01 KB
/
SignatureTests.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
module Fantomas.Tests.SignatureTests
open NUnit.Framework
open FsUnit
open Fantomas.CodeFormatter
open Fantomas.Tests.TestHelper
// the current behavior results in a compile error since "(string * string) list" is converted to "string * string list"
[<Test>]
let ``should keep the (string * string) list type signature in records``() =
formatSourceString false """type MSBuildParams =
{ Targets : string list
Properties : (string * string) list
MaxCpuCount : int option option
ToolsVersion : string option
Verbosity : MSBuildVerbosity option
FileLoggers : MSBuildFileLoggerConfig list option }
""" config
|> should equal """type MSBuildParams =
{ Targets : string list
Properties : (string * string) list
MaxCpuCount : int option option
ToolsVersion : string option
Verbosity : MSBuildVerbosity option
FileLoggers : MSBuildFileLoggerConfig list option }
"""
[<Test>]
let ``should keep the (string * string) list type signature in functions``() =
formatSourceString false """let MSBuildWithProjectProperties outputPath (targets : string)
(properties : string -> (string * string) list) projects = doingsomstuff
""" config
|> should equal """let MSBuildWithProjectProperties outputPath (targets : string)
(properties : string -> (string * string) list) projects = doingsomstuff
"""
[<Test>]
let ``should keep the string * string list type signature in functions``() =
formatSourceString false """let MSBuildWithProjectProperties outputPath (targets : string)
(properties : (string -> string) * string list) projects = doingsomstuff
""" config
|> should equal """let MSBuildWithProjectProperties outputPath (targets : string)
(properties : (string -> string) * string list) projects = doingsomstuff
"""
[<Test>]
let ``should not add parens in signature``() =
formatSourceString false """type Route =
{ Verb : string
Path : string
Handler : Map<string, string> -> HttpListenerContext -> string }
override x.ToString() = sprintf "%s %s" x.Verb x.Path
""" config
|> should equal """type Route =
{ Verb : string
Path : string
Handler : Map<string, string> -> HttpListenerContext -> string }
override x.ToString() = sprintf "%s %s" x.Verb x.Path
"""
[<Test>]
let ``should keep the string * string * string option type signature``() =
formatSourceString false """type DGML =
| Node of string
| Link of string * string * (string option)
""" config
|> should equal """type DGML =
| Node of string
| Link of string * string * string option
"""
[<Test>]
let ``should keep the (string option * Node) list type signature``() =
formatSourceString false """type Node =
{ Name : string;
NextNodes : (string option * Node) list }
""" { config with SemicolonAtEndOfLine = true }
|> should equal """type Node =
{ Name : string;
NextNodes : (string option * Node) list }
"""
[<Test>]
let ``should keep parentheses on the left of type signatures``() =
formatSourceString false """type IA =
abstract F: (unit -> Option<'T>) -> Option<'T>
type A () =
interface IA with
member x.F (f: unit -> _) = f ()
""" config
|> should equal """type IA =
abstract F : (unit -> Option<'T>) -> Option<'T>
type A() =
interface IA with
member x.F(f : unit -> _) = f()
"""
[<Test>]
let ``should not add parentheses around bare tuples``() =
formatSourceString true """
namespace TupleType
type C =
member P1 : int * string
/// def
member P2 : int
""" config
|> prepend newline
|> should equal """
namespace TupleType
type C =
member P1 : int * string
/// def
member P2 : int
"""
[<Test>]
let ``should keep global constraints in type signature``() =
formatSourceString true """
module Tainted
val GetHashCodeTainted : (Tainted<'T> -> int) when 'T : equality
""" config
|> prepend newline
|> should equal """
module Tainted
val GetHashCodeTainted : Tainted<'T> -> int when 'T : equality
"""