-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add VSI tests for Navigation Bars (#18478)
Add VSI tests for Navigation Bars
- Loading branch information
Ravi Chande
authored
Apr 6, 2017
1 parent
ad64d42
commit 9616765
Showing
7 changed files
with
488 additions
and
1 deletion.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpNavigationBar.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// 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 Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Shared.TestHooks; | ||
using Microsoft.VisualStudio.IntegrationTest.Utilities; | ||
using Roslyn.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Roslyn.VisualStudio.IntegrationTests.CSharp | ||
{ | ||
[Collection(nameof(SharedIntegrationHostFixture))] | ||
public class CSharpNavigationBar : AbstractEditorTest | ||
{ | ||
private const string TestSource = @" | ||
class C | ||
{ | ||
public void M(int i) { } | ||
private C $$this[int index] { get { return null; } set { } } | ||
public static bool operator ==(C c1, C c2) { return true; } | ||
public static bool operator !=(C c1, C c2) { return false; } | ||
} | ||
struct S | ||
{ | ||
int Foo() { } | ||
void Bar() { } | ||
}"; | ||
|
||
protected override string LanguageName => LanguageNames.CSharp; | ||
|
||
public CSharpNavigationBar(VisualStudioInstanceFactory instanceFactory) | ||
: base(instanceFactory, nameof(CSharpNavigationBar)) | ||
{ | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)] | ||
public void VerifyNavBar() | ||
{ | ||
SetUpEditor(TestSource); | ||
VisualStudio.Editor.PlaceCaret("this", charsOffset: 1); | ||
VisualStudio.Editor.ExpandMemberNavBar(); | ||
var expectedItems = new[] | ||
{ | ||
"M(int i)", | ||
"operator !=(C c1, C c2)", | ||
"operator ==(C c1, C c2)", | ||
"this[int index]" | ||
}; | ||
|
||
Assert.Equal(expectedItems, VisualStudio.Editor.GetMemberNavBarItems()); | ||
VisualStudio.Editor.SelectMemberNavBarItem("operator !=(C c1, C c2)"); | ||
|
||
VisualStudio.Editor.Verify.CurrentLineText("public static bool operator $$!=(C c1, C c2) { return false; }", assertCaretPosition: true, trimWhitespace: true); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)] | ||
public void VerifyNavBar2() | ||
{ | ||
SetUpEditor(TestSource); | ||
|
||
VerifyLeftSelected("C"); | ||
VerifyRightSelected("this[int index]"); | ||
|
||
VisualStudio.Editor.ExpandTypeNavBar(); | ||
var expectedItems = new[] | ||
{ | ||
"C", | ||
"S", | ||
}; | ||
|
||
VisualStudio.Editor.SelectTypeNavBarItem("S"); | ||
|
||
VerifyLeftSelected("S"); | ||
VerifyRightSelected("Foo()"); | ||
VisualStudio.Editor.Verify.CurrentLineText("$$struct S", assertCaretPosition: true, trimWhitespace: true); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)] | ||
public void VerifyNavBar3() | ||
{ | ||
SetUpEditor(@" | ||
struct S$$ | ||
{ | ||
int Foo() { } | ||
void Bar() { } | ||
}"); | ||
VisualStudio.Editor.ExpandMemberNavBar(); | ||
var expectedItems = new[] | ||
{ | ||
"Bar()", | ||
"Foo()", | ||
}; | ||
Assert.Equal(expectedItems, VisualStudio.Editor.GetMemberNavBarItems()); | ||
VisualStudio.Editor.SelectMemberNavBarItem("Bar()"); | ||
VisualStudio.Editor.Verify.CurrentLineText("void $$Bar() { }", assertCaretPosition: true, trimWhitespace: true); | ||
|
||
VisualStudio.ExecuteCommand("Edit.LineUp"); | ||
VerifyRightSelected("Foo()"); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)] | ||
public void TestSplitWindow() | ||
{ | ||
VisualStudio.Editor.SetText(@" | ||
class C | ||
{ | ||
public void M(int i) { } | ||
private C this[int index] { get { return null; } set { } } | ||
} | ||
struct S | ||
{ | ||
int Foo() { } | ||
void Bar() { } | ||
}"); | ||
VisualStudio.ExecuteCommand("Window.Split"); | ||
VisualStudio.Editor.PlaceCaret("this", charsOffset: 1); | ||
VerifyLeftSelected("C"); | ||
VerifyRightSelected("this[int index]"); | ||
VisualStudio.ExecuteCommand("Window.NextSplitPane"); | ||
VisualStudio.Editor.PlaceCaret("Foo", charsOffset: 1); | ||
VerifyLeftSelected("S"); | ||
VerifyRightSelected("Foo()"); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)] | ||
public void VerifyOption() | ||
{ | ||
VisualStudio.Workspace.SetFeatureOption("NavigationBarOptions", "ShowNavigationBar", "C#", "False"); | ||
Assert.False(VisualStudio.Editor.IsNavBarEnabled()); | ||
|
||
VisualStudio.Workspace.SetFeatureOption("NavigationBarOptions", "ShowNavigationBar", "C#", "True"); | ||
Assert.True(VisualStudio.Editor.IsNavBarEnabled()); | ||
} | ||
|
||
private void VerifyLeftSelected(string expected) | ||
{ | ||
Assert.Equal(expected, VisualStudio.Editor.GetTypeNavBarSelection()); | ||
} | ||
|
||
private void VerifyRightSelected(string expected) | ||
{ | ||
Assert.Equal(expected, VisualStudio.Editor.GetMemberNavBarSelection()); | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
src/VisualStudio/IntegrationTest/IntegrationTests/VisualBasic/BasicNavigationBar.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// 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 Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Shared.TestHooks; | ||
using Microsoft.VisualStudio.IntegrationTest.Utilities; | ||
using Roslyn.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Roslyn.VisualStudio.IntegrationTests.Basic | ||
{ | ||
[Collection(nameof(SharedIntegrationHostFixture))] | ||
public class BasicNavigationBar : AbstractEditorTest | ||
{ | ||
private const string TestSource = @" | ||
Class C | ||
Public WithEvents Domain As AppDomain | ||
Public Sub Foo() | ||
End Sub | ||
End Class | ||
Structure S | ||
Public Property A As Integer | ||
Public Property B As Integer | ||
End Structure"; | ||
|
||
protected override string LanguageName => LanguageNames.VisualBasic; | ||
|
||
public BasicNavigationBar(VisualStudioInstanceFactory instanceFactory) | ||
: base(instanceFactory, nameof(BasicNavigationBar)) | ||
{ | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)] | ||
public void VerifyNavBar() | ||
{ | ||
VisualStudio.Editor.SetText(TestSource); | ||
|
||
VisualStudio.Editor.PlaceCaret("Foo", charsOffset: 1); | ||
|
||
VerifyLeftSelected("C"); | ||
VerifyRightSelected("Foo"); | ||
|
||
VisualStudio.Editor.ExpandTypeNavBar(); | ||
var expectedItems = new[] | ||
{ | ||
"C", | ||
"Domain", | ||
"S" | ||
}; | ||
|
||
Assert.Equal(expectedItems, VisualStudio.Editor.GetTypeNavBarItems()); | ||
|
||
VisualStudio.Editor.SelectTypeNavBarItem("S"); | ||
|
||
VisualStudio.Editor.Verify.CaretPosition(112); | ||
VisualStudio.Editor.Verify.CurrentLineText("Structure S$$", assertCaretPosition: true); | ||
|
||
VisualStudio.ExecuteCommand("Edit.LineDown"); | ||
VerifyRightSelected("A"); | ||
|
||
VisualStudio.Editor.ExpandMemberNavBar(); | ||
expectedItems = new[] | ||
{ | ||
"A", | ||
"B", | ||
}; | ||
|
||
Assert.Equal(expectedItems, VisualStudio.Editor.GetMemberNavBarItems()); | ||
VisualStudio.Editor.SelectMemberNavBarItem("B"); | ||
VisualStudio.Editor.Verify.CaretPosition(169); | ||
VisualStudio.Editor.Verify.CurrentLineText("Public Property $$B As Integer", assertCaretPosition: true, trimWhitespace: true); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)] | ||
public void CodeSpit() | ||
{ | ||
VisualStudio.Editor.SetText(TestSource); | ||
|
||
VisualStudio.Editor.PlaceCaret("C", charsOffset: 1); | ||
VerifyLeftSelected("C"); | ||
VisualStudio.Editor.ExpandMemberNavBar(); | ||
Assert.Equal(new[] { "New", "Finalize", "Foo" }, VisualStudio.Editor.GetMemberNavBarItems()); | ||
VisualStudio.Editor.SelectMemberNavBarItem("New"); | ||
VisualStudio.Editor.Verify.TextContains(@" | ||
Public Sub New() | ||
End Sub"); | ||
VisualStudio.Editor.Verify.CaretPosition(78); // Caret is between New() and End Sub() in virtual whitespace | ||
VisualStudio.Editor.Verify.CurrentLineText("$$", assertCaretPosition: true); | ||
} | ||
|
||
[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)] | ||
public void VerifyOption() | ||
{ | ||
VisualStudio.Workspace.SetFeatureOption("NavigationBarOptions", "ShowNavigationBar", "Visual Basic", "False"); | ||
Assert.False(VisualStudio.Editor.IsNavBarEnabled()); | ||
|
||
VisualStudio.Workspace.SetFeatureOption("NavigationBarOptions", "ShowNavigationBar", "Visual Basic", "True"); | ||
Assert.True(VisualStudio.Editor.IsNavBarEnabled()); | ||
} | ||
|
||
private void VerifyLeftSelected(string expected) | ||
{ | ||
Assert.Equal(expected, VisualStudio.Editor.GetTypeNavBarSelection()); | ||
} | ||
|
||
private void VerifyRightSelected(string expected) | ||
{ | ||
Assert.Equal(expected, VisualStudio.Editor.GetMemberNavBarSelection()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.