Skip to content

Commit 411e995

Browse files
committed
Core.Tests: fix some snippets
* If a let declaration doesn't have any params, it isn't really a function; so let's add some () to fix them. * Funcs alone can't live inside a namespace, but rather a module. * For loops can't live inside a module, they need to be inside a function. * A function's last line cannot be a let declaration. * The public tuple snippet didn't need a main wrapper func. * No need for [<EntryPoint>] attributes in tests. * Better to use `module` than `open`/`namespace`, especially in tests that don't need the latter. * etc...
1 parent 29ddfa7 commit 411e995

File tree

6 files changed

+50
-43
lines changed

6 files changed

+50
-43
lines changed

tests/FSharpLint.Core.Tests/Rules/Conventions/AsyncExceptionWithoutReturn.fs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ type TestAsyncExceptionWithoutReturn() =
1111
[<Test>]
1212
member this.AsyncRaiseWithoutReturn() =
1313
this.Parse("""
14-
namespace Program
14+
module Program
1515
16-
let someAsyncFunction =
16+
let someAsyncFunction () =
1717
async {
1818
raise (new System.Exception("An error occurred."))
1919
return true
@@ -24,9 +24,9 @@ let someAsyncFunction =
2424
[<Test>]
2525
member this.AsyncRaiseWithReturn() =
2626
this.Parse("""
27-
namespace Program
27+
module Program
2828
29-
let someAsyncFunction =
29+
let someAsyncFunction () =
3030
async {
3131
return raise (new System.Exception("An error occurred."))
3232
}""")
@@ -36,9 +36,9 @@ let someAsyncFunction =
3636
[<Test>]
3737
member this.AsyncFailWithWithoutReturn() =
3838
this.Parse("""
39-
namespace Program
39+
module Program
4040
41-
let someAsyncFunction =
41+
let someAsyncFunction () =
4242
async {
4343
failwith "An error occurred."
4444
return true
@@ -49,9 +49,9 @@ let someAsyncFunction =
4949
[<Test>]
5050
member this.AsyncFailwithfWithoutReturn1() =
5151
this.Parse("""
52-
namespace Program
52+
module Program
5353
54-
let someAsyncFunction =
54+
let someAsyncFunction () =
5555
async {
5656
let errCode = 78
5757
failwithf "Dummy Error Message: %i" errCode
@@ -63,9 +63,9 @@ let someAsyncFunction =
6363
[<Test>]
6464
member this.AsyncFailwithfWithoutReturn2() =
6565
this.Parse("""
66-
namespace Program
66+
module Program
6767
68-
let someAsyncFunction =
68+
let someAsyncFunction () =
6969
async {
7070
let errCode = 78
7171
failwithf "Dummy Error Message: %i" errCode
@@ -76,9 +76,9 @@ let someAsyncFunction =
7676
[<Test>]
7777
member this.AsyncFailwithWithReturn() =
7878
this.Parse("""
79-
namespace Program
79+
module Program
8080
81-
let someAsyncFunction =
81+
let someAsyncFunction () =
8282
async {
8383
return failwith "An error occurred."
8484
}""")
@@ -88,9 +88,9 @@ let someAsyncFunction =
8888
[<Test>]
8989
member this.AsyncFailwithfWithReturn() =
9090
this.Parse("""
91-
namespace Program
91+
module Program
9292
93-
let someAsyncFunction =
93+
let someAsyncFunction () =
9494
async {
9595
let errCode = 78
9696
return failwithf "Dummy Error Message: %i" errCode
@@ -101,9 +101,9 @@ let someAsyncFunction =
101101
[<Test>]
102102
member this.AsyncRaiseWithReturnInnerExpression() =
103103
this.Parse("""
104-
namespace Program
104+
module Program
105105
106-
let someAsyncFunction =
106+
let someAsyncFunction () =
107107
async {
108108
if 2 = 2 then
109109
return raise (new System.Exception("An error occurred."))
@@ -116,9 +116,9 @@ let someAsyncFunction =
116116
[<Test>]
117117
member this.AsyncRaiseWithoutReturnInnerExpression() =
118118
this.Parse("""
119-
namespace Program
119+
module Program
120120
121-
let someAsyncFunction =
121+
let someAsyncFunction () =
122122
async {
123123
if 2 = 2 then
124124
raise (new System.Exception("An error occurred."))

tests/FSharpLint.Core.Tests/Rules/Conventions/AvoidTooShortNames.fs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type TestConventionsAvoidTooShortNames() =
1111
[<Test>]
1212
member this.AvoidTooShortNamesShouldNotProduceError1() =
1313
this.Parse """
14-
open System
14+
module Program
1515
1616
let foo = 1
1717
let bar baz =
@@ -24,7 +24,7 @@ let bar baz =
2424
[<Test>]
2525
member this.AvoidTooShortNamesShouldProduceError2() =
2626
this.Parse """
27-
open System
27+
module Program
2828
2929
let f = 1
3030
let bar baz =
@@ -37,7 +37,7 @@ let bar baz =
3737
[<Test>]
3838
member this.AvoidTooShortNamesShouldProduceError3() =
3939
this.Parse """
40-
open System
40+
module Program
4141
4242
let foo = 1
4343
let b baz n =
@@ -50,7 +50,7 @@ let b baz n =
5050
[<Test>]
5151
member this.AvoidTooShortNamesShouldProduceError4() =
5252
this.Parse """
53-
open System
53+
module Program
5454
5555
let foo = 1
5656
let bar b =
@@ -63,7 +63,7 @@ let bar b =
6363
[<Test>]
6464
member this.AvoidTooShortNamesShouldProduceError5() =
6565
this.Parse """
66-
open System
66+
module Program
6767
6868
let foo = 1
6969
let bar baz =
@@ -175,10 +175,12 @@ async {
175175
this.Parse """
176176
type SomeDU =
177177
| SomeMember of int * string * bool
178+
| SomeOtherMember of int
178179
179180
let fooFunction (arg: SomeDU) =
180181
match arg with
181182
| SomeDU.SomeMember(x, _, _) -> x
183+
| SomeDU.SomeOtherMember theInt -> theInt
182184
"""
183185

184186
Assert.IsTrue this.ErrorsExist

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Program
2121
2222
let main =
2323
let (Cat, _) = 1, 0
24+
()
2425
"""
2526

2627
Assert.IsTrue(this.ErrorExistsAt(5, 9))
@@ -256,7 +257,9 @@ let foo x = 0
256257
member this.ForLoopIdentifierIsCamelCase() =
257258
this.Parse """
258259
module Program
259-
for i = 10 downto 1 do System.Console.Write(i)
260+
261+
let someFunc() =
262+
for i = 10 downto 1 do System.Console.Write(i)
260263
"""
261264

262265
this.AssertNoWarnings()
@@ -265,16 +268,20 @@ for i = 10 downto 1 do System.Console.Write(i)
265268
member this.ForLoopIdentifierIsPascalCase() =
266269
this.Parse """
267270
module program
268-
for I = 10 downto 1 do System.Console.Write(I)
271+
272+
let someFunc() =
273+
for I = 10 downto 1 do System.Console.Write(I)
269274
"""
270275

271-
Assert.IsTrue(this.ErrorExistsAt(3, 4))
276+
Assert.IsTrue(this.ErrorExistsAt(5, 8))
272277

273278
[<Test>]
274279
member this.ForEachLoopIdentifierIsCamelCase() =
275280
this.Parse """
276281
module Program
277-
for i in 1..10 do System.Console.Write(i)
282+
283+
let someFunc() =
284+
for i in 1..10 do System.Console.Write(i)
278285
"""
279286

280287
this.AssertNoWarnings()
@@ -283,10 +290,12 @@ for i in 1..10 do System.Console.Write(i)
283290
member this.ForEachLoopIdentifierIsPascalCase() =
284291
this.Parse """
285292
module program
286-
for I in 1..10 do System.Console.Write(I)
293+
294+
let someFunc() =
295+
for I in 1..10 do System.Console.Write(I)
287296
"""
288297

289-
Assert.IsTrue(this.ErrorExistsAt(3, 4))
298+
Assert.IsTrue(this.ErrorExistsAt(5, 8))
290299

291300
[<Test>]
292301
member this.UnionCaseInBindingContainingPascalCaseValueGeneratesWarning() =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ extern int PyThreadState_SetAsyncExcLLP64(uint id, IntPtr exc)
4444
member this.PublicTupleIsCamelCase() =
4545
this.Parse """
4646
module Program
47-
let main =
48-
let (cat, _) = 1, 0
47+
48+
let (cat, _) = 1, 0
4949
"""
5050

5151
this.AssertNoWarnings()

tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ printf foo.Value
5353
[<Test>]
5454
member this.``Error for Option.Value (complex test case)``() =
5555
this.Parse """
56-
namespace Foo
57-
5856
module Program =
5957
let foo = None
6058
@@ -63,13 +61,12 @@ module Program =
6361
"""
6462

6563
Assert.IsTrue this.ErrorsExist
66-
Assert.IsTrue(this.ErrorExistsAt(8, 34))
64+
Assert.IsTrue(this.ErrorExistsAt(6, 34))
6765
this.AssertErrorWithMessageExists("Consider using pattern matching instead of partial function/method 'Option.Value'.")
6866

6967
[<Test>]
7068
member this.``No error for calling Value on ref type (regression)``() =
7169
this.Parse """
72-
namespace Foo
7370
module Program =
7471
let foo = None
7572
let bar = ref 0
@@ -83,7 +80,6 @@ module Program =
8380
[<Test>]
8481
member this.``Error for Option.Value (List.tryHead test case)``() =
8582
this.Parse """
86-
namespace Foo
8783
module Program =
8884
let foo = []
8985
@@ -92,20 +88,21 @@ module Program =
9288
"""
9389

9490
Assert.IsTrue this.ErrorsExist
95-
Assert.IsTrue(this.ErrorExistsAt(7, 34))
91+
Assert.IsTrue(this.ErrorExistsAt(6, 34))
9692
this.AssertErrorWithMessageExists("Consider using pattern matching instead of partial function/method 'Option.Value'.")
9793

9894
[<Test>]
9995
member this.``No error for value property in DU``() =
10096
this.Parse """
101-
namespace Foo
97+
module Program
10298
103-
module Program =
10499
type SomeTypeThatsNotOption =
105100
| Value of string
106101
| Count of int
107102
108-
let foo = SomeTypeThatsNotOption.Value
103+
let Foo (foo: SomeTypeThatsNotOption) =
104+
let foo = SomeTypeThatsNotOption.Value
105+
()
109106
"""
110107

111108
this.AssertNoWarnings()

tests/FSharpLint.Core.Tests/Rules/Conventions/UnneededRecKeyword.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ let rec Foo someParam =
3535
let rec Foo someParam =
3636
()
3737
38-
[<EntryPoint>]
39-
let main args =
38+
let Bar () =
4039
let Foo () =
4140
()
4241
4342
Foo()
44-
0
43+
()
4544
"""
4645

4746
Assert.IsTrue this.ErrorsExist

0 commit comments

Comments
 (0)