Skip to content

Commit 6ca4ebe

Browse files
committed
AsynchronousFunctionNames: added tests
For functions without explicit return types.
1 parent c5b40dd commit 6ca4ebe

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/FSharpLint.Core.Tests/Rules/Conventions/Naming/AsynchronousFunctionNames.fs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,54 @@ type Foo() =
175175

176176
Assert.IsTrue this.NoErrorsExist
177177

178+
[<Test>]
179+
member this.``Function without explicit type returning Async<'T> should give violations offering adding Async prefix``() =
180+
this.Parse """
181+
module Foo =
182+
let Bar() =
183+
async { return 1 }
184+
"""
185+
186+
Assert.IsTrue this.ErrorsExist
187+
StringAssert.Contains("AsyncBar", this.ErrorMsg)
188+
189+
[<Test>]
190+
member this.``Function without explicit type returning Task<'T> should give violations offering adding Async suffix``() =
191+
this.Parse """
192+
module Foo =
193+
let Bar() =
194+
task {}
195+
"""
196+
197+
Assert.IsTrue this.ErrorsExist
198+
StringAssert.Contains("BarAsync", this.ErrorMsg)
199+
200+
[<Test>]
201+
member this.``Function without explicit type returning Task should give violations offering adding Async suffix``() =
202+
this.Parse """
203+
open System.Threading.Tasks
204+
205+
module Foo =
206+
let Bar() =
207+
let Baz(): Task =
208+
null
209+
Baz()
210+
"""
211+
212+
Assert.IsTrue this.ErrorsExist
213+
StringAssert.Contains("BarAsync", this.ErrorMsg)
214+
215+
[<Test>]
216+
member this.``Method without explicit type returning Async<'T> should give violations offering adding Async prefix``() =
217+
this.Parse """
218+
type Foo() =
219+
member this.Bar() =
220+
async { return 1 }
221+
"""
222+
223+
Assert.IsTrue this.ErrorsExist
224+
StringAssert.Contains("AsyncBar", this.ErrorMsg)
225+
178226
[<TestFixture>]
179227
type TestAsynchronousFunctionNamesAllAPIs() =
180228
inherit TestAstNodeRuleBase.TestAstNodeRuleBase(AsynchronousFunctionNames.rule { Mode = AllAPIs })

0 commit comments

Comments
 (0)