Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes comparison of VB XML literals #75301

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax
SyntaxKind.FloatingLiteralToken,
SyntaxKind.IntegerLiteralToken,
SyntaxKind.InterpolatedStringTextToken,
SyntaxKind.StringLiteralToken
SyntaxKind.StringLiteralToken,
SyntaxKind.XmlTextLiteralToken,
SyntaxKind.XmlNameToken
Return String.Equals(DirectCast(before, Green.SyntaxToken).Text,
DirectCast(after, Green.SyntaxToken).Text,
StringComparison.Ordinal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.

Imports Roslyn.Test.Utilities

Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests

Public Class SyntaxEquivalenceTests
Expand Down Expand Up @@ -274,6 +276,46 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
VerifyNotEquivalent(tree1, tree2, topLevel:=False)
End Sub

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75231")>
Public Sub TestXmlLiteral_Text()
Dim tree1 = VisualBasicSyntaxTree.ParseText(NewLines("namespace N \n class C \n sub Goo() \n Dim x = <x>Text1</x> \n end sub \n end class \n end namespace"))
Dim tree2 = tree1.WithReplaceFirst("Text1", "Text2")
VerifyEquivalent(tree1, tree2, topLevel:=True)
VerifyNotEquivalent(tree1, tree2, topLevel:=False)
End Sub

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75231")>
Public Sub TestXmlLiteral_AttributeValue()
Dim tree1 = VisualBasicSyntaxTree.ParseText(NewLines("namespace N \n class C \n sub Goo() \n Dim x = <x a=""attr1"">Text</x> \n end sub \n end class \n end namespace"))
Dim tree2 = tree1.WithReplaceFirst("attr1", "attr2")
VerifyEquivalent(tree1, tree2, topLevel:=True)
VerifyNotEquivalent(tree1, tree2, topLevel:=False)
End Sub

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75231")>
Public Sub TestXmlLiteral_AttributeName()
Dim tree1 = VisualBasicSyntaxTree.ParseText(NewLines("namespace N \n class C \n sub Goo() \n Dim x = <x attr1=""v"">Text</x> \n end sub \n end class \n end namespace"))
Dim tree2 = tree1.WithReplaceFirst("attr1", "attr2")
VerifyEquivalent(tree1, tree2, topLevel:=True)
VerifyNotEquivalent(tree1, tree2, topLevel:=False)
End Sub

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75231")>
Public Sub TestXmlLiteral_CDATA()
Dim tree1 = VisualBasicSyntaxTree.ParseText(NewLines("namespace N \n class C \n sub Goo() \n Dim a = <x><![CDATA[Text1]]></x> \n end sub \n end class \n end namespace"))
Dim tree2 = tree1.WithReplaceFirst("Text1", "Text2")
VerifyEquivalent(tree1, tree2, topLevel:=True)
VerifyNotEquivalent(tree1, tree2, topLevel:=False)
End Sub

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75231")>
Public Sub TestXmlLiteral_Comment()
Dim tree1 = VisualBasicSyntaxTree.ParseText(NewLines("namespace N \n class C \n sub Goo() \n Dim a = <x><!--Text1--></x> \n end sub \n end class \n end namespace"))
Dim tree2 = tree1.WithReplaceFirst("Text1", "Text2")
VerifyEquivalent(tree1, tree2, topLevel:=True)
VerifyNotEquivalent(tree1, tree2, topLevel:=False)
End Sub

#Region "Field"

<Fact>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,90 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EditAndContinue.UnitTests
"Update [Resume Next]@80 -> [Resume]@65")
End Sub

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75231")>
Public Sub XmlLiteral_Text()
Dim src1 = "
Dim a = <x>Text1</x>
"
Dim src2 = "
Dim a = <x>Text2</x>
"
Dim edits = GetMethodEdits(src1, src2)

edits.VerifyEdits(
"Update [a = <x>Text1</x>]@14 -> [a = <x>Text2</x>]@14")
End Sub

<Fact>
Public Sub XmlLiteral_Node()
Dim src1 = "
Dim a = <x>Text</x>
"
Dim src2 = "
Dim a = <y>Text</y>
"
Dim edits = GetMethodEdits(src1, src2)

edits.VerifyEdits(
"Update [a = <x>Text</x>]@14 -> [a = <y>Text</y>]@14")
End Sub

<Fact>
Public Sub XmlLiteral_AttributeValue()
Dim src1 = "
Dim a = <x a=""attr1"">Text</x>
"
Dim src2 = "
Dim a = <x a=""attr2"">Text</x>
"
Dim edits = GetMethodEdits(src1, src2)

edits.VerifyEdits(
"Update [a = <x a=""attr1"">Text</x>]@14 -> [a = <x a=""attr2"">Text</x>]@14")
End Sub

<Fact>
Public Sub XmlLiteral_AttributeName()
Dim src1 = "
Dim a = <x a=""attr"">Text</x>
"
Dim src2 = "
Dim a = <x b=""attr"">Text</x>
"
Dim edits = GetMethodEdits(src1, src2)

edits.VerifyEdits(
"Update [a = <x a=""attr"">Text</x>]@14 -> [a = <x b=""attr"">Text</x>]@14")
End Sub

<Fact>
Public Sub XmlLiteral_CDATA()
Dim src1 = "
Dim a = <x><![CDATA[Text1]]></x>
"
Dim src2 = "
Dim a = <x><![CDATA[Text2]]></x>
"
Dim edits = GetMethodEdits(src1, src2)

edits.VerifyEdits(
"Update [a = <x><![CDATA[Text1]]></x>]@14 -> [a = <x><![CDATA[Text2]]></x>]@14")
End Sub

<Fact>
Public Sub XmlLiteral_Comment()
Dim src1 = "
Dim a = <x><!--Text1--></x>
"
Dim src2 = "
Dim a = <x><!--Text2--></x>
"
Dim edits = GetMethodEdits(src1, src2)

edits.VerifyEdits(
"Update [a = <x><!--Text1--></x>]@14 -> [a = <x><!--Text2--></x>]@14")
End Sub

#End Region

#Region "Select"
Expand Down
Loading