Skip to content

Commit 72354fc

Browse files
committed
SynchronousFunctionNames: added tests
For functions without explicit return types.
1 parent 4c701ea commit 72354fc

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,49 @@ type Foo() =
209209
"""
210210

211211
Assert.IsTrue this.NoErrorsExist
212+
213+
[<Test>]
214+
member this.``Non-asynchronous function without explicit type named Async* should give violations offering removing Async prefix``() =
215+
this.Parse """
216+
module Foo =
217+
let AsyncBar() =
218+
1
219+
"""
220+
221+
Assert.IsTrue this.ErrorsExist
222+
StringAssert.Contains("Bar", this.ErrorMsg)
223+
224+
[<Test>]
225+
member this.``Non-asynchronous function without explicit type named *Async should give violations offering removing Async suffix``() =
226+
this.Parse """
227+
module Foo =
228+
let BarAsync() =
229+
1
230+
"""
231+
232+
Assert.IsTrue this.ErrorsExist
233+
StringAssert.Contains("Bar", this.ErrorMsg)
234+
235+
[<Test>]
236+
member this.``Async functions without explicit type with Async prefix should give no violations``() =
237+
this.Parse """
238+
let AsyncFoo() =
239+
async { return 1 }
240+
let AsyncBar() =
241+
async { return () }
242+
let AsyncBaz() =
243+
async { do! Async.Sleep(1000) }
244+
"""
245+
246+
Assert.IsTrue this.NoErrorsExist
247+
248+
[<Test>]
249+
member this.``Functions without explicit type that return Task with Async suffix should give no violations``() =
250+
this.Parse """
251+
let FooAsync() =
252+
task {}
253+
let BarAsync() =
254+
task { return 1 }
255+
"""
256+
257+
Assert.IsTrue this.NoErrorsExist

0 commit comments

Comments
 (0)