Skip to content

Commit 0beb43d

Browse files
committed
Core.Tests: add tests for UsedUnderscorePrefixedElements quickfix
Added tests for suggested quick fix for UsedUnderscorePrefixedElements rule.
1 parent 7980a8c commit 0beb43d

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,64 @@ type CustomerName(firstName) =
124124
"""
125125

126126
Assert.IsFalse this.ErrorsExist
127+
128+
[<Test>]
129+
member this.``Used variable with underscore prefix should be renamed by removing underscore``() =
130+
let source = """
131+
module MyModule =
132+
let MyFunc () =
133+
let _random = System.Random()
134+
printfn "%A" _random
135+
()
136+
137+
let Func2 () =
138+
()"""
139+
140+
let expected = """
141+
module MyModule =
142+
let MyFunc () =
143+
let random = System.Random()
144+
printfn "%A" random
145+
()
146+
147+
let Func2 () =
148+
()"""
149+
150+
this.Parse source
151+
152+
let result = this.ApplyQuickFix source
153+
154+
Assert.AreEqual(expected, result)
155+
156+
[<Test>]
157+
member this.``Used variable with underscore prefix should not be renamed if such renaming clashes with existing variable``() =
158+
let source = """
159+
module MyModule =
160+
let MyFunc () =
161+
let random = 0
162+
let _random = System.Random()
163+
printfn "%A" _random
164+
() """
165+
166+
this.Parse source
167+
168+
let result = this.ApplyQuickFix source
169+
170+
Assert.AreEqual(source, result)
171+
172+
[<Test>]
173+
member this.``Used variable with underscore prefix should not be renamed if such renaming clashes with existing variable in outer scope``() =
174+
let source = """
175+
module MyModule =
176+
let random = 0
177+
178+
let MyFunc () =
179+
let _random = System.Random()
180+
printfn "%A" _random
181+
() """
182+
183+
this.Parse source
184+
185+
let result = this.ApplyQuickFix source
186+
187+
Assert.AreEqual(source, result)

0 commit comments

Comments
 (0)