File tree Expand file tree Collapse file tree
tests/FSharpLint.Core.Tests/Rules/Conventions Expand file tree Collapse file tree Original file line number Diff line number Diff 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)
You can’t perform that action at this time.
0 commit comments