提交 bd0b5d27 编写于 作者: A Allison Chou

Bug fix + add test

上级 1ff98f58
......@@ -530,7 +530,7 @@ End Module")
<WorkItem(529756, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529756")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInvertIf)>
Public Async Function TestOnCoditionOfSingleLineIf() As Task
Public Async Function TestOnConditionOfSingleLineIf() As Task
Await TestInRegularAndScriptAsync(
"Module Program
Sub Main(args As String())
......@@ -616,5 +616,31 @@ End Module
If Not a Then bMethod() Else aMethod()
")
End Function
<WorkItem(45177, "https://github.com/dotnet/roslyn/issues/45177")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInvertIf)>
Public Async Function TestWithMissingTrueStatementWithinUsing() As Task
Await TestInRegularAndScriptAsync(
"Module Program
Sub M(Disposable As IDisposable)
Dim x = True
Using Disposable
[||]If Not x Then End
End Using
Dim y = 0
End Sub
End Module",
"Module Program
Sub M(Disposable As IDisposable)
Dim x = True
Using Disposable
If x Then Else End
End Using
Dim y = 0
End Sub
End Module")
End Function
End Class
End Namespace
......@@ -54,14 +54,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.InvertIf
' That way the trailing comments/newlines at the end of the 'if' stay there,
' And the spaces after the true-part stay where they are.
Dim lastTrue = trueStatements.Last()
Dim lastFalse = falseStatements.Last()
Dim lastTrue = trueStatements.LastOrDefault()
Dim lastFalse = falseStatements.LastOrDefault()
Dim newLastTrue = lastTrue.WithTrailingTrivia(lastFalse.GetTrailingTrivia())
Dim newLastFalse = lastFalse.WithTrailingTrivia(lastTrue.GetTrailingTrivia())
If lastTrue IsNot Nothing And lastFalse IsNot Nothing Then
Dim newLastTrue = lastTrue.WithTrailingTrivia(lastFalse.GetTrailingTrivia())
Dim newLastFalse = lastFalse.WithTrailingTrivia(lastTrue.GetTrailingTrivia())
trueStatements = trueStatements.Replace(lastTrue, newLastTrue)
falseStatements = falseStatements.Replace(lastFalse, newLastFalse)
trueStatements = trueStatements.Replace(lastTrue, newLastTrue)
falseStatements = falseStatements.Replace(lastFalse, newLastFalse)
End If
End If
Dim updatedIf = ifNode _
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册