From 1e8c21b4778f5630d314e8de6b24453ba3da45aa Mon Sep 17 00:00:00 2001 From: Ravi Chande Date: Mon, 10 Apr 2017 13:42:03 -0700 Subject: [PATCH 1/2] Port reference highlighting tests --- src/EditorFeatures/Core/EditorFeatures.csproj | 1 + .../CSharp/CSharpReferenceHighlighting.cs | 71 ++++++++++++++++++ .../VisualBasic/BasicReferenceHighlighting.cs | 73 +++++++++++++++++++ .../VisualStudioIntegrationTests.csproj | 2 + 4 files changed, 147 insertions(+) create mode 100644 src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpReferenceHighlighting.cs create mode 100644 src/VisualStudio/IntegrationTest/IntegrationTests/VisualBasic/BasicReferenceHighlighting.cs diff --git a/src/EditorFeatures/Core/EditorFeatures.csproj b/src/EditorFeatures/Core/EditorFeatures.csproj index 7600a9f5a2b0c..ed647b250cb75 100644 --- a/src/EditorFeatures/Core/EditorFeatures.csproj +++ b/src/EditorFeatures/Core/EditorFeatures.csproj @@ -90,6 +90,7 @@ + diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpReferenceHighlighting.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpReferenceHighlighting.cs new file mode 100644 index 0000000000000..7dead19d807ee --- /dev/null +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpReferenceHighlighting.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Collections.Immutable; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting; +using Microsoft.CodeAnalysis.Shared.TestHooks; +using Microsoft.CodeAnalysis.Text; +using Microsoft.VisualStudio.IntegrationTest.Utilities; +using Microsoft.VisualStudio.IntegrationTest.Utilities.Input; +using Roslyn.Test.Utilities; +using Xunit; + +namespace Roslyn.VisualStudio.IntegrationTests.CSharp +{ + [Collection(nameof(SharedIntegrationHostFixture))] + public class CSharpReferenceHighlighting : AbstractEditorTest + { + protected override string LanguageName => LanguageNames.CSharp; + + public CSharpReferenceHighlighting(VisualStudioInstanceFactory instanceFactory) + : base(instanceFactory, nameof(CSharpReferenceHighlighting)) + { + } + + [Fact, Trait(Traits.Feature, Traits.Features.Classification)] + public void Highlighting() + { + var markup = @" +class {|definition:C|} +{ + void M({|reference:C|} c) where T : {|reference:C|} + { + {|reference:C|} c = new {|reference:C|}(); + } +}"; + Test.Utilities.MarkupTestFile.GetSpans(markup, out var text, out IDictionary> spans); + VisualStudio.Editor.SetText(text); + Verify("C", spans); + + // Verify tags disappear + VerifyNone("void"); + } + + private void Verify(string marker, IDictionary> spans) + { + VisualStudio.Editor.PlaceCaret(marker, charsOffset: -1); + VisualStudio.Workspace.WaitForAsyncOperations(string.Concat( + FeatureAttribute.SolutionCrawler, + FeatureAttribute.DiagnosticService, + FeatureAttribute.Classification, + FeatureAttribute.ReferenceHighlighting)); + + AssertEx.SetEqual(spans["reference"], VisualStudio.Editor.GetTagSpans(ReferenceHighlightTag.TagId)); + AssertEx.SetEqual(spans["definition"], VisualStudio.Editor.GetTagSpans(DefinitionHighlightTag.TagId)); + } + + private void VerifyNone(string marker) + { + VisualStudio.Editor.PlaceCaret(marker, charsOffset: -1); + VisualStudio.Workspace.WaitForAsyncOperations(string.Concat( + FeatureAttribute.SolutionCrawler, + FeatureAttribute.DiagnosticService, + FeatureAttribute.Classification, + FeatureAttribute.ReferenceHighlighting)); + + Assert.Empty(VisualStudio.Editor.GetTagSpans(ReferenceHighlightTag.TagId)); + Assert.Empty(VisualStudio.Editor.GetTagSpans(DefinitionHighlightTag.TagId)); + } + } +} \ No newline at end of file diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/VisualBasic/BasicReferenceHighlighting.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/VisualBasic/BasicReferenceHighlighting.cs new file mode 100644 index 0000000000000..4520ab6b597c7 --- /dev/null +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/VisualBasic/BasicReferenceHighlighting.cs @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Collections.Immutable; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting; +using Microsoft.CodeAnalysis.Shared.TestHooks; +using Microsoft.CodeAnalysis.Text; +using Microsoft.VisualStudio.IntegrationTest.Utilities; +using Microsoft.VisualStudio.IntegrationTest.Utilities.Input; +using Roslyn.Test.Utilities; +using Xunit; + +namespace Roslyn.VisualStudio.IntegrationTests.Basic +{ + [Collection(nameof(SharedIntegrationHostFixture))] + public class BasicReferenceHighlighting : AbstractEditorTest + { + protected override string LanguageName => LanguageNames.VisualBasic; + + public BasicReferenceHighlighting(VisualStudioInstanceFactory instanceFactory) + : base(instanceFactory, nameof(BasicReferenceHighlighting)) + { + } + + [Fact, Trait(Traits.Feature, Traits.Features.Classification)] + public void Highlighting() + { + var markup = @" +Class C + Dim {|definition:Foo|} as Int32 + Function M() + Console.WriteLine({|reference:Foo|}) + {|writtenReference:Foo|} = 4 + End Function +End Class"; + Test.Utilities.MarkupTestFile.GetSpans(markup, out var text, out IDictionary> spans); + VisualStudio.Editor.SetText(text); + Verify("Foo", spans); + + // Verify tags disappear + VerifyNone("4"); + } + + private void Verify(string marker, IDictionary> spans) + { + VisualStudio.Editor.PlaceCaret(marker, charsOffset: -1); + VisualStudio.Workspace.WaitForAsyncOperations(string.Concat( + FeatureAttribute.SolutionCrawler, + FeatureAttribute.DiagnosticService, + FeatureAttribute.Classification, + FeatureAttribute.ReferenceHighlighting)); + + AssertEx.SetEqual(spans["reference"], VisualStudio.Editor.GetTagSpans(ReferenceHighlightTag.TagId)); + AssertEx.SetEqual(spans["writtenReference"], VisualStudio.Editor.GetTagSpans(WrittenReferenceHighlightTag.TagId)); + AssertEx.SetEqual(spans["definition"], VisualStudio.Editor.GetTagSpans(DefinitionHighlightTag.TagId)); + } + + private void VerifyNone(string marker) + { + VisualStudio.Editor.PlaceCaret(marker, charsOffset: -1); + VisualStudio.Workspace.WaitForAsyncOperations(string.Concat( + FeatureAttribute.SolutionCrawler, + FeatureAttribute.DiagnosticService, + FeatureAttribute.Classification, + FeatureAttribute.ReferenceHighlighting)); + + Assert.Empty(VisualStudio.Editor.GetTagSpans(ReferenceHighlightTag.TagId)); + Assert.Empty(VisualStudio.Editor.GetTagSpans(WrittenReferenceHighlightTag.TagId)); + Assert.Empty(VisualStudio.Editor.GetTagSpans(DefinitionHighlightTag.TagId)); + } + } +} \ No newline at end of file diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/VisualStudioIntegrationTests.csproj b/src/VisualStudio/IntegrationTest/IntegrationTests/VisualStudioIntegrationTests.csproj index 6f772a4c09af2..fb9c8c9f55d40 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/VisualStudioIntegrationTests.csproj +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/VisualStudioIntegrationTests.csproj @@ -21,6 +21,7 @@ + @@ -62,6 +63,7 @@ + From 2fd042d49aea498b157662446e101744082f7975 Mon Sep 17 00:00:00 2001 From: Ravi Chande Date: Wed, 12 Apr 2017 10:02:57 -0700 Subject: [PATCH 2/2] Add tests for navigation and written reference highlighting --- .../CSharp/CSharpReferenceHighlighting.cs | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpReferenceHighlighting.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpReferenceHighlighting.cs index 7dead19d807ee..e216ac66345ab 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpReferenceHighlighting.cs +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpReferenceHighlighting.cs @@ -42,6 +42,46 @@ void M({|reference:C|} c) where T : {|reference:C|} VerifyNone("void"); } + [Fact, Trait(Traits.Feature, Traits.Features.Classification)] + public void WrittenReference() + { + var markup = @" +class C +{ + void M() + { + int {|definition:x|}; + {|writtenreference:x|} = 3; + } +}"; + Test.Utilities.MarkupTestFile.GetSpans(markup, out var text, out IDictionary> spans); + VisualStudio.Editor.SetText(text); + Verify("x", spans); + + // Verify tags disappear + VerifyNone("void"); + } + + [Fact, Trait(Traits.Feature, Traits.Features.Classification)] + public void Navigation() + { + var text = @" +class C +{ + void M() + { + int x; + x = 3; + } +}"; + VisualStudio.Editor.SetText(text); + VisualStudio.Editor.PlaceCaret("x"); + VisualStudio.Workspace.WaitForAsyncOperations(FeatureAttribute.ReferenceHighlighting); + VisualStudio.ExecuteCommand("Edit.NextHighlightedReference"); + VisualStudio.Workspace.WaitForAsyncOperations(FeatureAttribute.ReferenceHighlighting); + VisualStudio.Editor.Verify.CurrentLineText("x$$ = 3;", assertCaretPosition: true, trimWhitespace: true); + } + private void Verify(string marker, IDictionary> spans) { VisualStudio.Editor.PlaceCaret(marker, charsOffset: -1); @@ -50,9 +90,17 @@ private void Verify(string marker, IDictionary> FeatureAttribute.DiagnosticService, FeatureAttribute.Classification, FeatureAttribute.ReferenceHighlighting)); - - AssertEx.SetEqual(spans["reference"], VisualStudio.Editor.GetTagSpans(ReferenceHighlightTag.TagId)); AssertEx.SetEqual(spans["definition"], VisualStudio.Editor.GetTagSpans(DefinitionHighlightTag.TagId)); + + if (spans.ContainsKey("reference")) + { + AssertEx.SetEqual(spans["reference"], VisualStudio.Editor.GetTagSpans(ReferenceHighlightTag.TagId)); + } + + if (spans.ContainsKey("writtenreference")) + { + AssertEx.SetEqual(spans["writtenreference"], VisualStudio.Editor.GetTagSpans(WrittenReferenceHighlightTag.TagId)); + } } private void VerifyNone(string marker)