提交 cad5f7a1 编写于 作者: P Petr Houška

Add general tests for RefactoringHelpersService.

上级 296a333c
......@@ -4,6 +4,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editor.UnitTests.RefactoringHelpers;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.RefactoringHelpers
......@@ -14,15 +15,17 @@ public RefactoringHelpersTests(CSharpTestWorkspaceFixture workspaceFixture) : ba
{
}
#region Locations
[Fact]
public async Task Test1()
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestInTokenDirectlyUnderNode()
{
var testText = @"
class C
{
void M()
{
[||]{|result:C LocalFunction(C c)
{|result:C Local[||]Function(C c)
{
return null;
}|}
......@@ -32,7 +35,252 @@ void M()
}
[Fact]
public async Task Test2()
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestBeforeTokenDirectlyUnderNode()
{
var testText = @"
class C
{
void M()
{
{|result:C [||]LocalFunction(C c)
{
return null;
}|}
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestAfterTokenDirectlyUnderNode()
{
var testText = @"
class C
{
void M()
{
{|result:C [||]LocalFunction(C c)
{
return null;
}|}
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingInTokenUnderDifferentNode()
{
var testText = @"
class C
{
void M()
{
C[||] LocalFunction(C c)
{
return null;
}
}
}";
await TestMissingAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestClimbRightEdge()
{
var testText = @"
class C
{
void M()
{
{|result:C LocalFunction(C c)
{
return null;
}[||]|}
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestClimbLeftEdge()
{
var testText = @"
class C
{
void M()
{
{|result:[||]C LocalFunction(C c)
{
return null;
}|}
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestClimbLeftEdgeComments()
{
var testText = @"
class C
{
void M()
{
/// <summary>
/// Comment1
/// </summary>
{|result:[||]C LocalFunction(C c)
{
return null;
}|}
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingInAnotherChildNode()
{
var testText = @"
class C
{
void M()
{
C LocalFunction(C c)
{
[||]return null;
}
}
}";
await TestMissingAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingLocationAfter()
{
var testText = @"
class C
{
void M()
{
C LocalFunction(C c)
{
return null;
}
[||]
}
}";
await TestMissingAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingLocationBefore()
{
var testText = @"
class C
{
void M()
{
[||]
C LocalFunction(C c)
{
return null;
}
}
}";
await TestMissingAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingLocationBefore2()
{
var testText = @"
class C
{
void M()
{
var a = new object();[||]
C LocalFunction(C c)
{
return null;
}
}
}";
await TestMissingAsync<LocalFunctionStatementSyntax>(testText);
}
#endregion
#region Selections
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestSelectedTokenDirectlyUnderNode()
{
var testText = @"
class C
{
void M()
{
{|result:C [|LocalFunction|](C c)
{
return null;
}|}
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestPartiallySelectedTokenDirectlyUnderNode()
{
var testText = @"
class C
{
void M()
{
{|result:C Lo[|calFunct|]ion(C c)
{
return null;
}|}
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestSelectedMultipleTokensUnderNode()
{
var testText = @"
class C
{
void M()
{
{|result:[|C LocalFunction(C c)|]
{
return null;
}|}
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingSelectedMultipleTokensWithLowerCommonAncestor()
{
var testText = @"
class C
......@@ -48,5 +296,291 @@ C LocalFunction(C c)
await TestMissingAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestCompleteSelection()
{
var testText = @"
class C
{
void M()
{
{|result:[|C LocalFunction(C c)
{
return null;
}|]|}
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestOverSelection()
{
var testText = @"
class C
{
void M()
{
[|
{|result:C LocalFunction(C c)
{
return null;
}|}
|]var a = new object();
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestOverSelectionComments()
{
var testText = @"
class C
{
void M()
{
// Co[|mment1
{|result:C LocalFunction(C c)
{
return null;
}|}|]
}
}";
await TestAsync<LocalFunctionStatementSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingOverSelection()
{
var testText = @"
class C
{
void M()
{
[|
C LocalFunction(C c)
{
return null;
}
v|]ar a = new object();
}
}";
await TestMissingAsync<LocalFunctionStatementSyntax>(testText);
}
#endregion
#region Attributes
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestClimbLeftEdgeBeforeAttribute()
{
var testText = @"
using System;
class C
{
class TestAttribute : Attribute { }
// Comment1
[||]{|result:[Test]
void M()
{
}|}
}";
await TestAsync<MethodDeclarationSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestClimbLeftEdgeAfterAttribute()
{
var testText = @"
using System;
class C
{
class TestAttribute : Attribute { }
{|result:[Test]
[||]void M()
{
}|}
}";
await TestAsync<MethodDeclarationSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestClimbLeftEdgeAfterAttributeComments()
{
var testText = @"
using System;
class C
{
class TestAttribute : Attribute { }
// Comment1
{|result:[Test]
// Comment2
[||]void M()
{
}|}
}";
await TestAsync<MethodDeclarationSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestClimbLeftEdgeAfterAttributes()
{
var testText = @"
using System;
class C
{
class TestAttribute : Attribute { }
class Test2Attribute : Attribute { }
// Comment1
{|result:[Test]
[Test2]
// Comment2
[||]void M()
{
}|}
}";
await TestAsync<MethodDeclarationSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingBetweenAttributes()
{
var testText = @"
using System;
class C
{
class TestAttribute : Attribute { }
class Test2Attribute : Attribute { }
[Test]
[||][Test2]
void M()
{
}
}";
await TestMissingAsync<MethodDeclarationSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingBetweenInAttributes()
{
var testText = @"
using System;
class C
{
class TestAttribute : Attribute { }
[[||]Test]
void M()
{
}
}";
await TestMissingAsync<MethodDeclarationSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingSelectedAttributes()
{
var testText = @"
using System;
class C
{
class TestAttribute : Attribute { }
class Test2Attribute : Attribute { }
[|[Test]
[Test2]|]
void M()
{
}
}";
await TestMissingAsync<MethodDeclarationSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestMissingSelectedAttribute()
{
var testText = @"
using System;
class C
{
class TestAttribute : Attribute { }
[|[Test]|]
void M()
{
}
}";
await TestMissingAsync<MethodDeclarationSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestSelectedWholeNodeAndAttributes()
{
var testText = @"
using System;
class C
{
class TestAttribute : Attribute { }
class Test2Attribute : Attribute { }
// Comment1
[|{|result:[Test]
[Test2]
// Comment2
void M()
{
}|}|]
}";
await TestAsync<MethodDeclarationSyntax>(testText);
}
[Fact]
[WorkItem(35525, "https://github.com/dotnet/roslyn/issues/35525")]
public async Task TestSelectedWholeNodeWithoutAttributes()
{
var testText = @"
using System;
class C
{
class TestAttribute : Attribute { }
class Test2Attribute : Attribute { }
// Comment1
{|result:[Test]
[Test2]
// Comment2
[|void M()
{
}|]|}
}";
await TestAsync<MethodDeclarationSyntax>(testText);
}
#endregion
#region Extractions
#endregion
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册