Skip to content

Commit bb881c2

Browse files
webwarrior-wsMersho
andcommitted
Tests.Core: apply all suggested fixes
Make ApplyQuickFix method apply all fixes and not only first one. It's necessary when testing rules that can create more than one suggested fix. Co-authored-by: Mehrshad <[email protected]>
1 parent be6dcb6 commit bb881c2

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

tests/FSharpLint.Core.Tests/Rules/TestRuleBase.fs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,27 @@ type TestRuleBase () =
7575
Assert.IsFalse(this.ErrorsExist, "Expected no errors, but was: " + this.ErrorMsg)
7676

7777
member this.ApplyQuickFix (source:string) =
78-
let firstSuggestedFix =
78+
let suggestedFixes =
7979
suggestions
8080
|> Seq.choose (fun x -> x.Details.SuggestedFix)
81-
|> Seq.tryHead
82-
83-
match firstSuggestedFix |> Option.bind (fun x -> x.Value) with
84-
| Some(fix) ->
85-
let startIndex = ExpressionUtilities.findPos fix.FromRange.Start source
86-
let endIndex = ExpressionUtilities.findPos fix.FromRange.End source
87-
88-
match (startIndex, endIndex) with
89-
| (Some(startIndex), Some(endIndex)) ->
90-
(StringBuilder source)
91-
.Remove(startIndex, endIndex - startIndex)
92-
.Insert(startIndex, fix.ToText)
93-
.ToString()
94-
| _ -> source
95-
| None -> source
81+
82+
Seq.fold
83+
(fun (source: string) (lazyFix: Lazy<Option<SuggestedFix>>) ->
84+
match lazyFix.Value with
85+
| Some(fix) ->
86+
let startIndex = ExpressionUtilities.findPos fix.FromRange.Start source
87+
let endIndex = ExpressionUtilities.findPos fix.FromRange.End source
88+
89+
match (startIndex, endIndex) with
90+
| (Some(startIndex), Some(endIndex)) ->
91+
(StringBuilder source)
92+
.Remove(startIndex, endIndex - startIndex)
93+
.Insert(startIndex, fix.ToText)
94+
.ToString()
95+
| _ -> source
96+
| None -> source )
97+
source
98+
suggestedFixes
9699

97100
[<SetUp>]
98101
member __.SetUp() = suggestions.Clear()

0 commit comments

Comments
 (0)