forked from fsprojects/fantomas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterfaceTests.fs
120 lines (106 loc) · 3.31 KB
/
InterfaceTests.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
module Fantomas.Tests.InterfaceTests
open NUnit.Framework
open FsUnit
open Fantomas.CodeFormatter
open Fantomas.Tests.TestHelper
[<Test>]
let ``interfaces and inheritance``() =
formatSourceString false """
type IPrintable =
abstract member Print : unit -> unit
type SomeClass1(x: int, y: float) =
interface IPrintable with
member this.Print() = printfn "%d %f" x y
type Interface3 =
inherit Interface1
inherit Interface2
abstract member Method3 : int -> int""" config
|> prepend newline
|> should equal """
type IPrintable =
abstract Print : unit -> unit
type SomeClass1(x : int, y : float) =
interface IPrintable with
member this.Print() = printfn "%d %f" x y
type Interface3 =
inherit Interface1
inherit Interface2
abstract Method3 : int -> int
"""
[<Test>]
let ``should not add with to interface definitions with no members``() =
formatSourceString false """type Text(text : string) =
interface IDocument
interface Infrastucture with
member this.Serialize sb = sb.AppendFormat("\"{0}\"", escape v)
member this.ToXml() = v :> obj
""" config
|> should equal """type Text(text : string) =
interface IDocument
interface Infrastucture with
member this.Serialize sb = sb.AppendFormat("\"{0}\"", escape v)
member this.ToXml() = v :> obj
"""
[<Test>]
let ``object expressions``() =
formatSourceString false """let obj1 = { new System.Object() with member x.ToString() = "F#" }""" config
|> prepend newline
|> should equal """
let obj1 =
{ new System.Object() with
member x.ToString() = "F#" }
"""
[<Test>]
let ``object expressions and interfaces``() =
formatSourceString false """
let implementer() =
{ new ISecond with
member this.H() = ()
member this.J() = ()
interface IFirst with
member this.F() = ()
member this.G() = () }""" config
|> prepend newline
|> should equal """
let implementer() =
{ new ISecond with
member this.H() = ()
member this.J() = ()
interface IFirst with
member this.F() = ()
member this.G() = () }
"""
[<Test>]
let ``should not add with to interfaces with no members in object expressions``() =
formatSourceString false """
let f () =
{ new obj() with
member x.ToString() = "INotifyEnumerableInternal"
interface INotifyEnumerableInternal<'T>
interface IEnumerable<_> with
member x.GetEnumerator() = null }""" config
|> prepend newline
|> should equal """
let f() =
{ new obj() with
member x.ToString() = "INotifyEnumerableInternal"
interface INotifyEnumerableInternal<'T>
interface IEnumerable<_> with
member x.GetEnumerator() = null }
"""
[<Test>]
let ``should keep named arguments on abstract members``() =
formatSourceString false """type IThing =
abstract Foo : name:string * age:int -> bool
""" config
|> should equal """type IThing =
abstract Foo : name:string * age:int -> bool
"""
[<Test>]
let ``should not skip 'with get()' in indexers``() =
formatSourceString false """type Interface =
abstract Item : int -> char with get
""" config
|> should equal """type Interface =
abstract Item : int -> char with get
"""