Skip to content

Commit 8233e30

Browse files
committed
SimpleAsyncComplementaryHelpers: added tests
For functions without explicit return types.
1 parent 478e85b commit 8233e30

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,42 @@ module Bar =
175175

176176
Assert.IsTrue this.NoErrorsExist
177177

178+
[<Test>]
179+
member this.``Function AsyncBar without explicit type should give violations offering creation of BarAsync``() =
180+
this.Parse """
181+
module Foo =
182+
let AsyncBar() =
183+
async { return 0 }
184+
"""
185+
186+
Assert.IsTrue this.ErrorsExist
187+
StringAssert.Contains("BarAsync(): Task<int>", this.ErrorMsg)
188+
StringAssert.Contains("Async.StartAsTask(AsyncBar())", this.ErrorMsg)
189+
190+
[<Test>]
191+
member this.``Function BarAsync without explicit type should give violations offering creation of AsyncBar``() =
192+
this.Parse """
193+
module Foo =
194+
let BarAsync() =
195+
task { return 1 }
196+
"""
197+
198+
Assert.IsTrue this.ErrorsExist
199+
StringAssert.Contains("AsyncBar(): Async<int>", this.ErrorMsg)
200+
StringAssert.Contains("async { return Async.AwaitTask (BarAsync()) }", this.ErrorMsg)
201+
202+
[<Test>]
203+
member this.``Functions without explicit type that comply with conventions should not give violations``() =
204+
this.Parse """
205+
module Foo =
206+
let AsyncBar() =
207+
async { return 0 }
208+
let BarAsync() =
209+
Async.StartAsTask(AsyncBar())
210+
"""
211+
212+
Assert.IsTrue this.NoErrorsExist
213+
178214
[<TestFixture>]
179215
type TestSimpleAsyncComplementaryHelpersAllAPIs() =
180216
inherit TestAstNodeRuleBase.TestAstNodeRuleBase(SimpleAsyncComplementaryHelpers.rule { Mode = AllAPIs })

0 commit comments

Comments
 (0)