From af867c7ccc047b3b342e194825c6f6a6046747de Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 29 Nov 2024 13:33:03 -0800 Subject: [PATCH 1/3] Use implicit initializer if present to generate type properties --- .../GenerateType/GenerateTypeTests.cs | 8 +- .../GenerateTypeCodeFixProvider.cs | 30 ++--- .../GenerateType/CSharpGenerateTypeService.cs | 106 +++++++----------- .../AbstractGenerateTypeService.cs | 4 - .../VisualBasicGenerateTypeService.vb | 10 +- 5 files changed, 54 insertions(+), 104 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs b/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs index 669ac6f76c832..ede03e12ca8c6 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs @@ -23,13 +23,9 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.GenerateTypeTests; [Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)] -public partial class GenerateTypeTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest +public sealed partial class GenerateTypeTests(ITestOutputHelper logger) + : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest(logger) { - public GenerateTypeTests(ITestOutputHelper logger) - : base(logger) - { - } - internal override (DiagnosticAnalyzer?, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace) => (null, new GenerateTypeCodeFixProvider()); diff --git a/src/Features/CSharp/Portable/CodeFixes/GenerateType/GenerateTypeCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/GenerateType/GenerateTypeCodeFixProvider.cs index 1e08fed0e35b8..217fdfbb42de1 100644 --- a/src/Features/CSharp/Portable/CodeFixes/GenerateType/GenerateTypeCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/CodeFixes/GenerateType/GenerateTypeCodeFixProvider.cs @@ -10,7 +10,6 @@ using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CodeFixes.GenerateMember; -using Microsoft.CodeAnalysis.CodeGeneration; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; @@ -21,7 +20,9 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.GenerateType; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.GenerateType), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.GenerateVariable)] -internal class GenerateTypeCodeFixProvider : AbstractGenerateMemberCodeFixProvider +[method: ImportingConstructor] +[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] +internal sealed class GenerateTypeCodeFixProvider() : AbstractGenerateMemberCodeFixProvider { private const string CS0103 = nameof(CS0103); // error CS0103: The name 'Goo' does not exist in the current context private const string CS0117 = nameof(CS0117); // error CS0117: 'x' does not contain a definition for 'y' @@ -32,29 +33,16 @@ internal class GenerateTypeCodeFixProvider : AbstractGenerateMemberCodeFixProvid private const string CS0426 = nameof(CS0426); // error CS0426: The type name 'S' does not exist in the type 'Program' private const string CS0616 = nameof(CS0616); // error CS0616: 'x' is not an attribute class - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] - public GenerateTypeCodeFixProvider() - { - } - public override ImmutableArray FixableDiagnosticIds - { - get { return [CS0103, CS0117, CS0234, CS0246, CS0305, CS0308, CS0426, CS0616, IDEDiagnosticIds.UnboundIdentifierId]; } - } + => [CS0103, CS0117, CS0234, CS0246, CS0305, CS0308, CS0426, CS0616, IDEDiagnosticIds.UnboundIdentifierId]; protected override bool IsCandidate(SyntaxNode node, SyntaxToken token, Diagnostic diagnostic) - { - switch (node) + => node switch { - case QualifiedNameSyntax or MemberAccessExpressionSyntax: - return true; - case SimpleNameSyntax simple: - return !simple.IsParentKind(SyntaxKind.QualifiedName); - } - - return false; - } + QualifiedNameSyntax or MemberAccessExpressionSyntax => true, + SimpleNameSyntax simple => !simple.IsParentKind(SyntaxKind.QualifiedName), + _ => false, + }; protected override SyntaxNode? GetTargetNode(SyntaxNode node) => ((ExpressionSyntax)node).GetRightmostName(); diff --git a/src/Features/CSharp/Portable/GenerateType/CSharpGenerateTypeService.cs b/src/Features/CSharp/Portable/GenerateType/CSharpGenerateTypeService.cs index 468e73304c84f..13c7499f84f3d 100644 --- a/src/Features/CSharp/Portable/GenerateType/CSharpGenerateTypeService.cs +++ b/src/Features/CSharp/Portable/GenerateType/CSharpGenerateTypeService.cs @@ -30,15 +30,11 @@ namespace Microsoft.CodeAnalysis.CSharp.GenerateType; [ExportLanguageService(typeof(IGenerateTypeService), LanguageNames.CSharp), Shared] -internal class CSharpGenerateTypeService : +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpGenerateTypeService() : AbstractGenerateTypeService { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpGenerateTypeService() - { - } - protected override string DefaultFileExtension => ".cs"; protected override ExpressionSyntax GetLeftSideOfDot(SimpleNameSyntax simpleName) @@ -88,28 +84,22 @@ protected override bool IsInValueTypeConstraintContext( protected override bool IsInInterfaceList(ExpressionSyntax expression) { - if (expression is TypeSyntax && - expression.Parent is BaseTypeSyntax baseType && - baseType.Parent is BaseListSyntax baseList && + if (expression is TypeSyntax { Parent: BaseTypeSyntax { Parent: BaseListSyntax baseList } baseType } && baseType.Type == expression) { // If it's after the first item, then it's definitely an interface. if (baseList.Types[0] != expression.Parent) - { return true; - } // If it's in the base list of an interface or struct, then it's definitely an // interface. - return baseList?.Parent.Kind() is + return baseList.Parent.Kind() is SyntaxKind.InterfaceDeclaration or SyntaxKind.StructDeclaration or SyntaxKind.RecordStructDeclaration; } - if (expression is TypeSyntax && - expression.Parent is TypeConstraintSyntax typeConstraint && - typeConstraint.Parent is TypeParameterConstraintClauseSyntax constraintClause) + if (expression is TypeSyntax { Parent: TypeConstraintSyntax { Parent: TypeParameterConstraintClauseSyntax constraintClause } typeConstraint }) { var index = constraintClause.Constraints.IndexOf(typeConstraint); @@ -121,9 +111,7 @@ expression.Parent is TypeConstraintSyntax typeConstraint && } protected override bool TryGetNameParts(ExpressionSyntax expression, out IList nameParts) - { - return expression.TryGetNameParts(out nameParts); - } + => expression.TryGetNameParts(out nameParts); protected override bool TryInitializeState( SemanticDocument document, @@ -134,14 +122,10 @@ protected override bool TryInitializeState( generateTypeServiceStateOptions = new GenerateTypeServiceStateOptions(); if (simpleName.IsVar) - { return false; - } if (SyntaxFacts.IsAliasQualifier(simpleName)) - { return false; - } // Never offer if we're in a using directive, unless its a static using. The feeling here is that it's highly // unlikely that this would be a location where a user would be wanting to generate @@ -149,18 +133,14 @@ protected override bool TryInitializeState( // isn't available for some reason (i.e. a missing reference). var usingDirectiveSyntax = simpleName.GetAncestorOrThis(); if (usingDirectiveSyntax != null && usingDirectiveSyntax.StaticKeyword.Kind() != SyntaxKind.StaticKeyword) - { return false; - } ExpressionSyntax nameOrMemberAccessExpression = null; if (simpleName.IsRightSideOfDot()) { // This simplename comes from the cref if (simpleName.IsParentKind(SyntaxKind.NameMemberCref)) - { return false; - } nameOrMemberAccessExpression = generateTypeServiceStateOptions.NameOrMemberAccessExpression = (ExpressionSyntax)simpleName.Parent; @@ -183,9 +163,9 @@ SyntaxKind.GenericName or } // BUG(5712): Don't offer generate type in an enum's base list. - if (nameOrMemberAccessExpression.Parent is BaseTypeSyntax && + if (nameOrMemberAccessExpression.Parent is BaseTypeSyntax baseType && nameOrMemberAccessExpression.Parent.IsParentKind(SyntaxKind.BaseList) && - ((BaseTypeSyntax)nameOrMemberAccessExpression.Parent).Type == nameOrMemberAccessExpression && + baseType.Type == nameOrMemberAccessExpression && nameOrMemberAccessExpression.Parent.Parent.IsParentKind(SyntaxKind.EnumDeclaration)) { return false; @@ -210,17 +190,13 @@ SyntaxKind.GenericName or generateTypeServiceStateOptions.IsDelegateAllowed = false; if (!isExpressionOrStatementContext) - { return false; - } if (!simpleName.IsLeftSideOfDot() && !simpleName.IsInsideNameOfExpression(semanticModel, cancellationToken)) { if (nameOrMemberAccessExpression == null || !nameOrMemberAccessExpression.IsKind(SyntaxKind.SimpleMemberAccessExpression) || !simpleName.IsRightSideOfDot()) - { return false; - } var leftSymbol = semanticModel.GetSymbolInfo(((MemberAccessExpressionSyntax)nameOrMemberAccessExpression).Expression, cancellationToken).Symbol; var token = simpleName.GetLastToken().GetNextToken(); @@ -271,11 +247,8 @@ fieldDeclaration.Parent is CompilationUnitSyntax && if (simpleName.Parent is QualifiedNameSyntax parent) { var leftSymbol = semanticModel.GetSymbolInfo(parent.Left, cancellationToken).Symbol; - if (leftSymbol != null && leftSymbol.IsKind(SymbolKind.Namespace)) - { generateTypeServiceStateOptions.IsMembersWithModule = true; - } } } } @@ -374,9 +347,9 @@ fieldDeclaration.Parent is CompilationUnitSyntax && // Func lambda = () => { return 0; }; // var s4 = new MyD3(lambda); - if (nameOrMemberAccessExpression.Parent is ObjectCreationExpressionSyntax) + if (nameOrMemberAccessExpression.Parent is ObjectCreationExpressionSyntax objectCreationExpressionOpt) { - var objectCreationExpressionOpt = generateTypeServiceStateOptions.ObjectCreationExpressionOpt = (ObjectCreationExpressionSyntax)nameOrMemberAccessExpression.Parent; + generateTypeServiceStateOptions.ObjectCreationExpressionOpt = objectCreationExpressionOpt; // Enum and Interface not Allowed in Object Creation Expression generateTypeServiceStateOptions.IsInterfaceOrEnumNotAllowedInTypeContext = true; @@ -384,9 +357,7 @@ fieldDeclaration.Parent is CompilationUnitSyntax && if (objectCreationExpressionOpt.ArgumentList != null) { if (objectCreationExpressionOpt.ArgumentList.CloseParenToken.IsMissing) - { return false; - } // Get the Method symbol for the Delegate to be created if (generateTypeServiceStateOptions.IsDelegateAllowed && @@ -400,49 +371,54 @@ fieldDeclaration.Parent is CompilationUnitSyntax && } } - if (objectCreationExpressionOpt.Initializer != null) - { - foreach (var expression in objectCreationExpressionOpt.Initializer.Expressions) - { - if (expression is not AssignmentExpressionSyntax simpleAssignmentExpression) - { - continue; - } - - if (simpleAssignmentExpression.Left is not SimpleNameSyntax name) - { - continue; - } + var initializer = objectCreationExpressionOpt.Initializer; + AddPropertiesToInitialize(generateTypeServiceStateOptions, initializer); + } - generateTypeServiceStateOptions.PropertiesToGenerate.Add(name); - } - } + // Check for `NewType t = new() { ... }` and initialize properties if present + if (nameOrMemberAccessExpression.Parent is VariableDeclarationSyntax + { + Variables: [{ Initializer.Value: ImplicitObjectCreationExpressionSyntax { Initializer: { } implicitInitializer } }, ..] + }) + { + AddPropertiesToInitialize(generateTypeServiceStateOptions, implicitInitializer); } if (generateTypeServiceStateOptions.IsDelegateAllowed) { // MyD1 z1 = goo; - if (nameOrMemberAccessExpression.Parent is VariableDeclarationSyntax variableDeclaration && - variableDeclaration.Variables.Count != 0) + if (nameOrMemberAccessExpression.Parent is VariableDeclarationSyntax variableDeclaration) { var firstVarDeclWithInitializer = variableDeclaration.Variables.FirstOrDefault(var => var.Initializer != null && var.Initializer.Value != null); - if (firstVarDeclWithInitializer != null && firstVarDeclWithInitializer.Initializer != null && firstVarDeclWithInitializer.Initializer.Value != null) - { + if (firstVarDeclWithInitializer != null) generateTypeServiceStateOptions.DelegateCreationMethodSymbol = GetMethodSymbolIfPresent(semanticModel, firstVarDeclWithInitializer.Initializer.Value, cancellationToken); - } } // var w1 = (MyD1)goo; - if (nameOrMemberAccessExpression.Parent is CastExpressionSyntax castExpression && - castExpression.Expression != null) - { + if (nameOrMemberAccessExpression.Parent is CastExpressionSyntax { Expression: not null } castExpression) generateTypeServiceStateOptions.DelegateCreationMethodSymbol = GetMethodSymbolIfPresent(semanticModel, castExpression.Expression, cancellationToken); - } } return true; } + private static void AddPropertiesToInitialize(GenerateTypeServiceStateOptions generateTypeServiceStateOptions, InitializerExpressionSyntax initializer) + { + if (initializer != null) + { + foreach (var expression in initializer.Expressions) + { + if (expression is not AssignmentExpressionSyntax simpleAssignmentExpression) + continue; + + if (simpleAssignmentExpression.Left is not SimpleNameSyntax name) + continue; + + generateTypeServiceStateOptions.PropertiesToGenerate.Add(name); + } + } + } + private static IMethodSymbol GetMethodSymbolIfPresent(SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken) { if (expression == null) diff --git a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs index 3653f01c7db78..054b2366767d8 100644 --- a/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs +++ b/src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.cs @@ -33,10 +33,6 @@ internal abstract partial class AbstractGenerateTypeService argumentList); diff --git a/src/Features/VisualBasic/Portable/GenerateType/VisualBasicGenerateTypeService.vb b/src/Features/VisualBasic/Portable/GenerateType/VisualBasicGenerateTypeService.vb index f0bf267e39a6f..045323189d8d5 100644 --- a/src/Features/VisualBasic/Portable/GenerateType/VisualBasicGenerateTypeService.vb +++ b/src/Features/VisualBasic/Portable/GenerateType/VisualBasicGenerateTypeService.vb @@ -9,7 +9,6 @@ Imports Microsoft.CodeAnalysis.AddImport Imports Microsoft.CodeAnalysis.CodeGeneration Imports Microsoft.CodeAnalysis.Editing Imports Microsoft.CodeAnalysis.Formatting -Imports Microsoft.CodeAnalysis.GenerateMember.GenerateConstructor Imports Microsoft.CodeAnalysis.GenerateType Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.LanguageService @@ -18,11 +17,10 @@ Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.Utilities Imports Microsoft.CodeAnalysis.VisualBasic.Extensions.ContextQuery Imports Microsoft.CodeAnalysis.VisualBasic.Syntax -Imports Microsoft.CodeAnalysis.VisualBasic.Utilities Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateType - Partial Friend Class VisualBasicGenerateTypeService + Partial Friend NotInheritable Class VisualBasicGenerateTypeService Inherits AbstractGenerateTypeService(Of VisualBasicGenerateTypeService, SimpleNameSyntax, ObjectCreationExpressionSyntax, ExpressionSyntax, TypeBlockSyntax, ArgumentSyntax) @@ -30,11 +28,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateType Public Sub New() End Sub - Protected Overrides ReadOnly Property DefaultFileExtension As String - Get - Return ".vb" - End Get - End Property + Protected Overrides ReadOnly Property DefaultFileExtension As String = ".vb" Protected Overrides Function GenerateParameterNames(semanticModel As SemanticModel, arguments As IList(Of ArgumentSyntax), cancellationToken As CancellationToken) As IList(Of ParameterName) Return semanticModel.GenerateParameterNames(arguments, reservedNames:=Nothing, cancellationToken:=cancellationToken) From cf8d5e491ff7f5d1f249829dbf744cfe6b0e5d09 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 29 Nov 2024 13:41:02 -0800 Subject: [PATCH 2/3] Update tests --- .../GenerateType/GenerateTypeTests.cs | 8490 +++++++++-------- 1 file changed, 4606 insertions(+), 3884 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs b/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs index ede03e12ca8c6..3f4ca027bdc65 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs @@ -44,299 +44,361 @@ protected override TestComposition GetComposition() public async Task TestGenerateTypeParameterFromArgumentInferT() { await TestInRegularAndScriptAsync( -@"class Program -{ - void Main() - { - [|Goo|] f; - } -}", -@"class Program -{ - void Main() - { - Goo f; - } -} + """ + class Program + { + void Main() + { + [|Goo|] f; + } + } + """, + """ + class Program + { + void Main() + { + Goo f; + } + } -internal class Goo -{ -}", -index: 1); + internal class Goo + { + } + """, + index: 1); } [Fact] public async Task TestGenerateClassFromTypeParameter() { await TestInRegularAndScriptAsync( -@"class Class -{ - System.Action<[|Employee|]> employees; -}", -@"class Class -{ - System.Action employees; + """ + class Class + { + System.Action<[|Employee|]> employees; + } + """, + """ + class Class + { + System.Action employees; - private class Employee - { - } -}", -index: 2); + private class Employee + { + } + } + """, + index: 2); } [Fact] public async Task TestGenerateInternalClassFromASingleConstraintClause() { await TestInRegularAndScriptAsync( -@"class EmployeeList where T : [|Employee|], new() -{ -}", -@"class EmployeeList where T : Employee, new() -{ -} + """ + class EmployeeList where T : [|Employee|], new() + { + } + """, + """ + class EmployeeList where T : Employee, new() + { + } -internal class Employee -{ -}", -index: 1); + internal class Employee + { + } + """, + index: 1); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18240")] public async Task TestGeneratePublicClassFromASingleConstraintClause() { await TestInRegularAndScriptAsync( -@"public class EmployeeList where T : [|Employee|], new() -{ -}", -@"public class EmployeeList where T : Employee, new() -{ -} + """ + public class EmployeeList where T : [|Employee|], new() + { + } + """, + """ + public class EmployeeList where T : Employee, new() + { + } -public class Employee -{ -}", -index: 1); + public class Employee + { + } + """, + index: 1); } [Fact] public async Task NegativeTestGenerateClassFromConstructorConstraint() { await TestMissingInRegularAndScriptAsync( -@"class EmployeeList where T : Employee, [|new()|] -{ -}"); + """ + class EmployeeList where T : Employee, [|new()|] + { + } + """); } [Fact] public async Task TestGenerateInternalClassFromMultipleTypeConstraintClauses() { await TestInRegularAndScriptAsync( -@"class Derived - where U : struct - where T : [|Base|], new() -{ -}", -@"class Derived - where U : struct - where T : Base, new() -{ -} + """ + class Derived + where U : struct + where T : [|Base|], new() + { + } + """, + """ + class Derived + where U : struct + where T : Base, new() + { + } -internal class Base -{ -}", -index: 1); + internal class Base + { + } + """, + index: 1); } [Fact] public async Task TestGeneratePublicClassFromMultipleTypeConstraintClauses() { await TestInRegularAndScriptAsync( -@"public class Derived - where U : struct - where T : [|Base|], new() -{ -}", -@"public class Derived - where U : struct - where T : Base, new() -{ -} + """ + public class Derived + where U : struct + where T : [|Base|], new() + { + } + """, + """ + public class Derived + where U : struct + where T : Base, new() + { + } -public class Base -{ -}", -index: 1); + public class Base + { + } + """, + index: 1); } [Fact] public async Task NegativeTestGenerateClassFromClassOrStructConstraint() { await TestMissingInRegularAndScriptAsync( -@"class Derived - where U : [|struct|] - where T : Base, new() -{ -}"); + """ + class Derived + where U : [|struct|] + where T : Base, new() + { + } + """); } [Fact] public async Task TestAbsenceOfGenerateIntoInvokingTypeForConstraintList() { await TestActionCountAsync( -@"class EmployeeList where T : [|Employee|] -{ -}", -count: 3, -parameters: new TestParameters(Options.Regular)); + """ + class EmployeeList where T : [|Employee|] + { + } + """, + count: 3, + parameters: new TestParameters(Options.Regular)); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18240")] public async Task TestGenerateInternalClassFromASingleConstraintClauseInterface() { await TestInRegularAndScriptAsync( -@"interface IEmployeeList where T : [|Employee|], new() -{ -}", -@"interface IEmployeeList where T : Employee, new() -{ -} + """ + interface IEmployeeList where T : [|Employee|], new() + { + } + """, + """ + interface IEmployeeList where T : Employee, new() + { + } -internal class Employee -{ -}", -index: 1); + internal class Employee + { + } + """, + index: 1); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18240")] public async Task TestGeneratePublicClassFromASingleConstraintClausePublicInterface() { await TestInRegularAndScriptAsync( -@"public interface IEmployeeList where T : [|Employee|], new() -{ -}", -@"public interface IEmployeeList where T : Employee, new() -{ -} + """ + public interface IEmployeeList where T : [|Employee|], new() + { + } + """, + """ + public interface IEmployeeList where T : Employee, new() + { + } -public class Employee -{ -}", -index: 1); + public class Employee + { + } + """, + index: 1); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18240")] public async Task TestGenerateInternalClassFromASingleConstraintClauseInternalDelegate() { await TestInRegularAndScriptAsync( -@"class Employee -{ - internal delegate void Action() where T : [|Command|]; -}", -@"class Employee -{ - internal delegate void Action() where T : Command; -} + """ + class Employee + { + internal delegate void Action() where T : [|Command|]; + } + """, + """ + class Employee + { + internal delegate void Action() where T : Command; + } -internal class Command -{ -}", -index: 1); + internal class Command + { + } + """, + index: 1); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18240")] public async Task TestGenerateInternalClassFromASingleConstraintClausePublicDelegate() { await TestInRegularAndScriptAsync( -@"class Employee -{ - public delegate void Action() where T : [|Command|]; -}", -@"class Employee -{ - public delegate void Action() where T : Command; -} + """ + class Employee + { + public delegate void Action() where T : [|Command|]; + } + """, + """ + class Employee + { + public delegate void Action() where T : Command; + } -internal class Command -{ -}", -index: 1); + internal class Command + { + } + """, + index: 1); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18240")] public async Task TestGenerateInternalClassFromASingleConstraintClauseInternalMethod() { await TestInRegularAndScriptAsync( -@"class Employee -{ - internal void Action() where T : [|Command|] {} -}", -@"class Employee -{ - internal void Action() where T : Command {} -} + """ + class Employee + { + internal void Action() where T : [|Command|] {} + } + """, + """ + class Employee + { + internal void Action() where T : Command {} + } -internal class Command -{ -}", -index: 1); + internal class Command + { + } + """, + index: 1); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18240")] public async Task TestGenerateInternalClassFromASingleConstraintClausePublicMethod() { await TestInRegularAndScriptAsync( -@"class Employee -{ - public void Action() where T : [|Command|] {} -}", -@"class Employee -{ - public void Action() where T : Command {} -} + """ + class Employee + { + public void Action() where T : [|Command|] {} + } + """, + """ + class Employee + { + public void Action() where T : Command {} + } -internal class Command -{ -}", -index: 1); + internal class Command + { + } + """, + index: 1); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18240")] public async Task TestGenerateInternalClassFromASingleConstraintClauseMethod() { await TestInRegularAndScriptAsync( -@"class Employee -{ - void Action() where T : [|Command|] {} -}", -@"class Employee -{ - void Action() where T : Command {} -} + """ + class Employee + { + void Action() where T : [|Command|] {} + } + """, + """ + class Employee + { + void Action() where T : Command {} + } -internal class Command -{ -}", -index: 1); + internal class Command + { + } + """, + index: 1); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18240")] public async Task TestGenerateInternalClassFromASingleConstraintClauseMethodInInterface() { await TestInRegularAndScriptAsync( -@"interface Employee -{ - void Action() where T : [|Command|] {} -}", -@"interface Employee -{ - void Action() where T : Command {} -} + """ + interface Employee + { + void Action() where T : [|Command|] {} + } + """, + """ + interface Employee + { + void Action() where T : Command {} + } -internal class Command -{ -}", -index: 1); + internal class Command + { + } + """, + index: 1); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/18240")] @@ -351,31 +413,35 @@ internal class Command public async Task TestGenerateInternalClassFromASingleConstraintClauseNestedClass(string middleAccessibility, string accessibility, string generatedAccessibility) { await TestInRegularAndScriptAsync( -$@"public class A -{{ - {middleAccessibility} class B - {{ - {accessibility} class C where T : [|D|] - {{ + $$""" + public class A + { + {{middleAccessibility}} class B + { + {{accessibility}} class C where T : [|D|] + { - }} - }} -}}", -$@"public class A -{{ - {middleAccessibility} class B - {{ - {accessibility} class C where T : D - {{ + } + } + } + """, + $$""" + public class A + { + {{middleAccessibility}} class B + { + {{accessibility}} class C where T : D + { - }} - }} -}} + } + } + } -{generatedAccessibility} class D -{{ -}}", -index: 1); + {{generatedAccessibility}} class D + { + } + """, + index: 1); } #endregion @@ -386,42 +452,50 @@ await TestInRegularAndScriptAsync( public async Task TestGenerateClassFromParenthesizedLambdaExpressionsParameter() { await TestInRegularAndScriptAsync( -@"class Class -{ - Func l = ([|Employee|] e, int age) => e.Age > age; -}", -@"class Class -{ - Func l = (Employee e, int age) => e.Age > age; + """ + class Class + { + Func l = ([|Employee|] e, int age) => e.Age > age; + } + """, + """ + class Class + { + Func l = (Employee e, int age) => e.Age > age; - private class Employee - { - } -}", -index: 2); + private class Employee + { + } + } + """, + index: 2); } [Fact] public async Task TestGenerateClassFromParenthesizedLambdaExpressionsBody() { await TestInRegularAndScriptAsync( -@"class Class -{ - System.Action l = (Class e, int age) => { - [|Wage|] w; - }; -}", -@"class Class -{ - System.Action l = (Class e, int age) => { - Wage w; - }; + """ + class Class + { + System.Action l = (Class e, int age) => { + [|Wage|] w; + }; + } + """, + """ + class Class + { + System.Action l = (Class e, int age) => { + Wage w; + }; - private class Wage - { - } -}", -index: 2); + private class Wage + { + } + } + """, + index: 2); } #endregion @@ -430,474 +504,388 @@ private class Wage public async Task TestGenerateClassFromFieldDeclarationIntoSameType() { await TestInRegularAndScriptAsync( -@"class Class -{ - [|Goo|] f; -}", -@"class Class -{ - Goo f; + """ + class Class + { + [|Goo|] f; + } + """, + """ + class Class + { + Goo f; - private class Goo - { - } -}", -index: 2); + private class Goo + { + } + } + """, + index: 2); } [Fact] public async Task TestGenerateClassFromNullableFieldDeclarationIntoSameType() { await TestInRegularAndScriptAsync( -@"#nullable enable -class Class -{ - [|Goo?|] f; -}", -@"#nullable enable -class Class -{ - Goo? f; + """ + #nullable enable + class Class + { + [|Goo?|] f; + } + """, + """ + #nullable enable + class Class + { + Goo? f; - private class Goo - { - } -}", -index: 2); + private class Goo + { + } + } + """, + index: 2); } [WpfFact] public async Task TestGenerateClassFromFieldDeclarationIntoGlobalNamespace() { await TestAddDocumentInRegularAndScriptAsync( -@"class Program { void Main ( ) { [|Goo|] f ; } } ", -@"internal class Goo -{ -}", -expectedContainers: ImmutableArray.Empty, -expectedDocumentName: "Goo.cs"); + @"class Program { void Main ( ) { [|Goo|] f ; } } ", + """ + internal class Goo + { + } + """, + expectedContainers: ImmutableArray.Empty, + expectedDocumentName: "Goo.cs"); } [WpfFact] public async Task TestGenerateClassFromFieldDeclarationIntoCustomNamespace() { await TestAddDocumentInRegularAndScriptAsync( -@"class Class { [|TestNamespace|].Goo f; }", -@"namespace TestNamespace -{ - internal class Goo - { - } -}", -expectedContainers: ImmutableArray.Create("TestNamespace"), -expectedDocumentName: "Goo.cs"); + @"class Class { [|TestNamespace|].Goo f; }", + """ + namespace TestNamespace + { + internal class Goo + { + } + } + """, + expectedContainers: ImmutableArray.Create("TestNamespace"), + expectedDocumentName: "Goo.cs"); } [Fact] public async Task TestGenerateClassFromFieldDeclarationIntoSameNamespace() { await TestInRegularAndScriptAsync( -@"class Class -{ - [|Goo|] f; -}", -@"class Class -{ - Goo f; -} + """ + class Class + { + [|Goo|] f; + } + """, + """ + class Class + { + Goo f; + } -internal class Goo -{ -}", -index: 1); + internal class Goo + { + } + """, + index: 1); } [Fact] public async Task TestGenerateClassWithCtorFromObjectCreation() { await TestInRegularAndScriptAsync( -@"class Class -{ - Goo f = new [|Goo|](); -}", -@"class Class -{ - Goo f = new Goo(); - - private class Goo - { - public Goo() - { - } - } -}", -index: 2); - } + """ + class Class + { + Goo f = new [|Goo|](); + } + """, + """ + class Class + { + Goo f = new Goo(); - [Fact] + private class Goo + { + public Goo() + { + } + } + } + """, + index: 2); + } + + [Fact] public async Task TestGenerateClassWithCtorFromObjectCreationWithTuple() { await TestInRegularAndScriptAsync( -@"class Class -{ - var f = new [|Generated|]((1, 2)); -}", -@"class Class -{ - var f = new Generated((1, 2)); + """ + class Class + { + var f = new [|Generated|]((1, 2)); + } + """, + """ + class Class + { + var f = new Generated((1, 2)); - private class Generated - { - private (int, int) value; + private class Generated + { + private (int, int) value; - public Generated((int, int) value) - { - this.value = value; - } - } -}", -index: 2); + public Generated((int, int) value) + { + this.value = value; + } + } + } + """, + index: 2); } [Fact] public async Task TestGenerateClassWithCtorFromObjectCreationWithTupleWithNames() { await TestInRegularAndScriptAsync( -@"class Class -{ - var f = new [|Generated|]((a: 1, b: 2, 3)); -}", -@"class Class -{ - var f = new Generated((a: 1, b: 2, 3)); + """ + class Class + { + var f = new [|Generated|]((a: 1, b: 2, 3)); + } + """, + """ + class Class + { + var f = new Generated((a: 1, b: 2, 3)); - private class Generated - { - private (int a, int b, int) value; + private class Generated + { + private (int a, int b, int) value; - public Generated((int a, int b, int) value) - { - this.value = value; - } - } -}", -index: 2); + public Generated((int a, int b, int) value) + { + this.value = value; + } + } + } + """, + index: 2); } [Fact] public async Task TestGenerateClassFromBaseList() { await TestInRegularAndScriptAsync( -@"class Class : [|BaseClass|] -{ -}", -@"class Class : BaseClass -{ -} + """ + class Class : [|BaseClass|] + { + } + """, + """ + class Class : BaseClass + { + } -internal class BaseClass -{ -}", -index: 1); + internal class BaseClass + { + } + """, + index: 1); } [Fact] public async Task TestGenerateClassFromMethodParameters() { await TestInRegularAndScriptAsync( -@"class Class -{ - void Method([|Goo|] f) - { - } -}", -@"class Class -{ - void Method(Goo f) - { - } + """ + class Class + { + void Method([|Goo|] f) + { + } + } + """, + """ + class Class + { + void Method(Goo f) + { + } - private class Goo - { - } -}", -index: 2); + private class Goo + { + } + } + """, + index: 2); } [Fact] public async Task TestGenerateClassFromMethodReturnType() { await TestInRegularAndScriptAsync( -@"class Class -{ - [|Goo|] Method() - { - } -}", -@"class Class -{ - Goo Method() - { - } + """ + class Class + { + [|Goo|] Method() + { + } + } + """, + """ + class Class + { + Goo Method() + { + } - private class Goo - { - } -}", -index: 2); + private class Goo + { + } + } + """, + index: 2); } [Fact] public async Task TestGenerateClassFromAttribute() { await TestInRegularAndScriptAsync( -@"class Class -{ - [[|Obsolete|]] - void Method() - { - } -}", -@"using System; + """ + class Class + { + [[|Obsolete|]] + void Method() + { + } + } + """, + """ + using System; -class Class -{ - [Obsolete] - void Method() - { - } + class Class + { + [Obsolete] + void Method() + { + } - private class ObsoleteAttribute : Attribute - { - } -}", -index: 2); + private class ObsoleteAttribute : Attribute + { + } + } + """, + index: 2); } [Fact] public async Task TestGenerateClassFromExpandedAttribute() { await TestInRegularAndScriptAsync( -@"class Class -{ - [[|ObsoleteAttribute|]] - void Method() - { - } -}", -@"using System; + """ + class Class + { + [[|ObsoleteAttribute|]] + void Method() + { + } + } + """, + """ + using System; -class Class -{ - [ObsoleteAttribute] - void Method() - { - } + class Class + { + [ObsoleteAttribute] + void Method() + { + } - private class ObsoleteAttribute : Attribute - { - } -}", -index: 2); + private class ObsoleteAttribute : Attribute + { + } + } + """, + index: 2); } [Fact] public async Task TestGenerateClassFromCatchClause() { await TestInRegularAndScriptAsync( -@"class Class -{ - void Method() - { - try - { - } - catch ([|ExType|]) - { - } - } -}", -@"using System; -using System.Runtime.Serialization; + """ + class Class + { + void Method() + { + try + { + } + catch ([|ExType|]) + { + } + } + } + """, + """ + using System; + using System.Runtime.Serialization; -class Class -{ - void Method() - { - try - { - } - catch (ExType) - { - } - } + class Class + { + void Method() + { + try + { + } + catch (ExType) + { + } + } - [Serializable] - private class ExType : Exception - { - public ExType() - { - } + [Serializable] + private class ExType : Exception + { + public ExType() + { + } - public ExType(string message) : base(message) - { - } + public ExType(string message) : base(message) + { + } - public ExType(string message, Exception innerException) : base(message, innerException) - { - } + public ExType(string message, Exception innerException) : base(message, innerException) + { + } - protected ExType(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - } -}", -index: 2); + protected ExType(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } + } + """, + index: 2); } [Fact] public async Task TestGenerateClassFromThrowStatement() { await TestInRegularAndScriptAsync( -@"class Class -{ - void Method() - { - throw new [|ExType|](); - } -}", -@"using System; -using System.Runtime.Serialization; - -class Class -{ - void Method() - { - throw new ExType(); - } - - [Serializable] - private class ExType : Exception - { - public ExType() - { - } - - public ExType(string message) : base(message) - { - } - - public ExType(string message, Exception innerException) : base(message, innerException) - { - } - - protected ExType(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - } -}", -index: 2); - } - - [Fact] - public async Task TestGenerateClassFromThrowStatementWithDifferentArg() - { - await TestInRegularAndScriptAsync( -@"class Class -{ - void Method() - { - throw new [|ExType|](1); - } -}", -@"using System; -using System.Runtime.Serialization; - -class Class -{ - void Method() - { - throw new ExType(1); - } - - [Serializable] - private class ExType : Exception - { - private int v; - - public ExType() - { - } - - public ExType(int v) - { - this.v = v; - } - - public ExType(string message) : base(message) - { - } - - public ExType(string message, Exception innerException) : base(message, innerException) - { - } - - protected ExType(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - } -}", -index: 2); - } - - [Fact] - public async Task TestGenerateClassFromThrowStatementWithMatchingArg() - { - await TestInRegularAndScriptAsync( -@"class Class -{ - void Method() - { - throw new [|ExType|](""message""); - } -}", -@"using System; -using System.Runtime.Serialization; - -class Class -{ - void Method() - { - throw new ExType(""message""); - } - - [Serializable] - private class ExType : Exception - { - public ExType() - { - } - - public ExType(string message) : base(message) - { - } - - public ExType(string message, Exception innerException) : base(message, innerException) - { - } - - protected ExType(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - } -}", -index: 2); - } - - [Fact] - public async Task TestGenerateClassFromThrowStatementOnModernDotNet_NoObsoleteConstructor() - { - var source = """ + """ class Class { void Method() @@ -905,16 +893,10 @@ void Method() throw new [|ExType|](); } } - """; - - await TestInRegularAndScriptAsync($""" - - - {source} - - - """, """ + """, + """ using System; + using System.Runtime.Serialization; class Class { @@ -937,1968 +919,2354 @@ public ExType(string message) : base(message) public ExType(string message, Exception innerException) : base(message, innerException) { } + + protected ExType(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } } - """, index: 2); + """, + index: 2); } [Fact] - public async Task TestAbsenceOfGenerateIntoInvokingTypeForBaseList() - { - await TestActionCountAsync( -@"class Class : [|BaseClass|] -{ -}", -count: 3, -parameters: new TestParameters(Options.Regular)); - } - - [Fact] - public async Task TestGenerateClassFromUsingStatement() + public async Task TestGenerateClassFromThrowStatementWithDifferentArg() { await TestInRegularAndScriptAsync( -@"class Class -{ - void Method() - { - using ([|Goo|] f = new Goo()) - { - } + """ + class Class + { + void Method() + { + throw new [|ExType|](1); + } + } + """, + """ + using System; + using System.Runtime.Serialization; + + class Class + { + void Method() + { + throw new ExType(1); + } + + [Serializable] + private class ExType : Exception + { + private int v; + + public ExType() + { + } + + public ExType(int v) + { + this.v = v; + } + + public ExType(string message) : base(message) + { + } + + public ExType(string message, Exception innerException) : base(message, innerException) + { + } + + protected ExType(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } + } + """, + index: 2); } -}", -@"class Class -{ - void Method() + + [Fact] + public async Task TestGenerateClassFromThrowStatementWithMatchingArg() { - using (Goo f = new Goo()) - { - } + await TestInRegularAndScriptAsync( + """ + class Class + { + void Method() + { + throw new [|ExType|]("message"); + } + } + """, + """ + using System; + using System.Runtime.Serialization; + + class Class + { + void Method() + { + throw new ExType("message"); + } + + [Serializable] + private class ExType : Exception + { + public ExType() + { + } + + public ExType(string message) : base(message) + { + } + + public ExType(string message, Exception innerException) : base(message, innerException) + { + } + + protected ExType(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } + } + """, + index: 2); } - private class Goo + [Fact] + public async Task TestGenerateClassFromThrowStatementOnModernDotNet_NoObsoleteConstructor() { - } -}", -index: 2); + var source = """ + class Class + { + void Method() + { + throw new [|ExType|](); + } + } + """; + + await TestInRegularAndScriptAsync($""" + + + {source} + + + """, """ + using System; + + class Class + { + void Method() + { + throw new ExType(); + } + + [Serializable] + private class ExType : Exception + { + public ExType() + { + } + + public ExType(string message) : base(message) + { + } + + public ExType(string message, Exception innerException) : base(message, innerException) + { + } + } + } + """, index: 2); } [Fact] - public async Task TestGenerateClassFromForeachStatement() - { - await TestInRegularAndScriptAsync( -@"class Class -{ - void Method() + public async Task TestAbsenceOfGenerateIntoInvokingTypeForBaseList() { - foreach ([|Employee|] e in empList) - { - } + await TestActionCountAsync( + """ + class Class : [|BaseClass|] + { + } + """, + count: 3, + parameters: new TestParameters(Options.Regular)); } -}", -@"class Class -{ - void Method() + + [Fact] + public async Task TestGenerateClassFromUsingStatement() { - foreach (Employee e in empList) - { - } + await TestInRegularAndScriptAsync( + """ + class Class + { + void Method() + { + using ([|Goo|] f = new Goo()) + { + } + } + } + """, + """ + class Class + { + void Method() + { + using (Goo f = new Goo()) + { + } + } + + private class Goo + { + } + } + """, + index: 2); } - private class Employee + [Fact] + public async Task TestGenerateClassFromForeachStatement() { - } -}", -index: 2); + await TestInRegularAndScriptAsync( + """ + class Class + { + void Method() + { + foreach ([|Employee|] e in empList) + { + } + } + } + """, + """ + class Class + { + void Method() + { + foreach (Employee e in empList) + { + } + } + + private class Employee + { + } + } + """, + index: 2); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538346")] public async Task TestGenerateClassWhereKeywordBecomesTypeName() { await TestInRegularAndScriptAsync( -@"class Class -{ - [|@class|] c; -}", -@"class Class -{ - @class c; + """ + class Class + { + [|@class|] c; + } + """, + """ + class Class + { + @class c; - private class @class - { - } -}", -index: 2); + private class @class + { + } + } + """, + index: 2); } [Fact] public async Task NegativeTestGenerateClassOnContextualKeyword() { await TestInRegularAndScriptAsync( -@"class Class -{ - [|@Goo|] c; -}", -@"class Class -{ - @Goo c; + """ + class Class + { + [|@Goo|] c; + } + """, + """ + class Class + { + @Goo c; - private class Goo - { - } -}", -index: 2); + private class Goo + { + } + } + """, + index: 2); } [Fact] public async Task NegativeTestGenerateClassOnFrameworkTypes() { await TestMissingInRegularAndScriptAsync( -@"class Class -{ - void Method() - { - [|System|].Console.Write(5); - } -}"); + """ + class Class + { + void Method() + { + [|System|].Console.Write(5); + } + } + """); await TestMissingInRegularAndScriptAsync( -@"class Class -{ - void Method() - { - System.[|Console|].Write(5); - } -}"); + """ + class Class + { + void Method() + { + System.[|Console|].Write(5); + } + } + """); await TestMissingInRegularAndScriptAsync( -@"class Class -{ - void Method() - { - System.Console.[|Write|](5); - } -}"); + """ + class Class + { + void Method() + { + System.Console.[|Write|](5); + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538409")] public async Task GenerateIntoRightPart() { await TestInRegularAndScriptAsync( -@"partial class Class -{ -} + """ + partial class Class + { + } -partial class Class -{ - [|C|] c; -}", -@"partial class Class -{ -} + partial class Class + { + [|C|] c; + } + """, + """ + partial class Class + { + } -partial class Class -{ - C c; + partial class Class + { + C c; - private class C - { - } -}", -index: 2); + private class C + { + } + } + """, + index: 2); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538408")] public async Task GenerateTypeIntoCompilationUnit() { await TestInRegularAndScriptAsync( -@"class Class -{ - [|C|] c; + """ + class Class + { + [|C|] c; - void Main() - { - } -}", -@"class Class -{ - C c; + void Main() + { + } + } + """, + """ + class Class + { + C c; - void Main() - { - } -} + void Main() + { + } + } -internal class C -{ -}", -index: 1); + internal class C + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538408")] public async Task GenerateTypeIntoNamespace() { await TestInRegularAndScriptAsync( -@"namespace N -{ - class Class - { - [|C|] c; + """ + namespace N + { + class Class + { + [|C|] c; - void Main() - { - } - } -}", -@"namespace N -{ - class Class - { - C c; + void Main() + { + } + } + } + """, + """ + namespace N + { + class Class + { + C c; - void Main() - { - } - } + void Main() + { + } + } - internal class C - { - } -}", -index: 1); + internal class C + { + } + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538115")] public async Task GenerateTypeWithPreprocessor() { await TestInRegularAndScriptAsync( -@"class C -{ -#if true - void Goo([|A|] x) { } -#else -#endif -}", -@"class C -{ -#if true - void Goo(A x) { } + """ + class C + { + #if true + void Goo([|A|] x) { } + #else + #endif + } + """, + """ + class C + { + #if true + void Goo(A x) { } - private class A - { - } -#else -#endif -}", -index: 2); + private class A + { + } + #else + #endif + } + """, + index: 2); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538495")] public async Task GenerateTypeIntoContainingNamespace() { await TestInRegularAndScriptAsync( -@"namespace N -{ - class Class - { - N.[|C|] c; - } -}", -@"namespace N -{ - class Class - { - N.C c; - } + """ + namespace N + { + class Class + { + N.[|C|] c; + } + } + """, + """ + namespace N + { + class Class + { + N.C c; + } - internal class C - { - } -}", -index: 1); + internal class C + { + } + } + """, + index: 1); } [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538516")] public async Task TestGenerateClassFromIntoNewNamespace() { await TestAddDocumentInRegularAndScriptAsync( -@"class Class { static void Main(string[] args) { [|N|].C c; } }", -@"namespace N -{ - internal class C - { - } -}", -expectedContainers: ImmutableArray.Create("N"), -expectedDocumentName: "C.cs"); + @"class Class { static void Main(string[] args) { [|N|].C c; } }", + """ + namespace N + { + internal class C + { + } + } + """, + expectedContainers: ImmutableArray.Create("N"), + expectedDocumentName: "C.cs"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538558")] public async Task NegativeTestGlobalAlias() { await TestMissingInRegularAndScriptAsync( -@"class Class -{ - void Method() - { - [|global|]::System.String s; - } -}"); + """ + class Class + { + void Method() + { + [|global|]::System.String s; + } + } + """); await TestMissingInRegularAndScriptAsync( -@"class Class -{ - void Method() - { - global::[|System|].String s; - } -}"); + """ + class Class + { + void Method() + { + global::[|System|].String s; + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538069")] public async Task GenerateTypeFromArrayCreation1() { await TestAsync( -@"class A -{ - void Goo() - { - A[] x = new [|C|][] { }; - } -}", -@"class A -{ - void Goo() - { - A[] x = new C[] { }; - } -} + """ + class A + { + void Goo() + { + A[] x = new [|C|][] { }; + } + } + """, + """ + class A + { + void Goo() + { + A[] x = new C[] { }; + } + } -internal class C : A -{ -}", -index: 1, -parseOptions: null); + internal class C : A + { + } + """, + index: 1, + parseOptions: null); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538069")] public async Task GenerateTypeFromArrayCreation2() { await TestAsync( -@"class A -{ - void Goo() - { - A[][] x = new [|C|][][] { }; - } -}", -@"class A -{ - void Goo() - { - A[][] x = new C[][] { }; - } -} + """ + class A + { + void Goo() + { + A[][] x = new [|C|][][] { }; + } + } + """, + """ + class A + { + void Goo() + { + A[][] x = new C[][] { }; + } + } -internal class C : A -{ -}", -index: 1, -parseOptions: null); + internal class C : A + { + } + """, + index: 1, + parseOptions: null); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538069")] public async Task GenerateTypeFromArrayCreation3() { await TestAsync( -@"class A -{ - void Goo() - { - A[] x = new [|C|][][] { }; - } -}", -@"class A -{ - void Goo() - { - A[] x = new C[][] { }; - } -} + """ + class A + { + void Goo() + { + A[] x = new [|C|][][] { }; + } + } + """, + """ + class A + { + void Goo() + { + A[] x = new C[][] { }; + } + } -internal class C -{ -}", -index: 1, -parseOptions: null); + internal class C + { + } + """, + index: 1, + parseOptions: null); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539329")] public async Task NegativeTestNotInUsingDirective() { await TestMissingInRegularAndScriptAsync( -@"using [|A|];"); + @"using [|A|];"); await TestMissingInRegularAndScriptAsync( -@"using [|A.B|];"); + @"using [|A.B|];"); await TestMissingInRegularAndScriptAsync( -@"using [|A|].B;"); + @"using [|A|].B;"); await TestMissingInRegularAndScriptAsync( -@"using A.[|B|];"); + @"using A.[|B|];"); await TestMissingInRegularAndScriptAsync( -@"using X = [|A|];"); + @"using X = [|A|];"); } [Fact] public async Task GenerateSimpleConstructor() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M() - { - new [|T|](); - } -}", -@"class Class -{ - void M() - { - new T(); - } -} + """ + class Class + { + void M() + { + new [|T|](); + } + } + """, + """ + class Class + { + void M() + { + new T(); + } + } -internal class T -{ - public T() - { - } -}", -index: 1); + internal class T + { + public T() + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithValueParameter() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M() - { - new [|T|](1); - } -}", -@"class Class -{ - void M() - { - new T(1); - } -} + """ + class Class + { + void M() + { + new [|T|](1); + } + } + """, + """ + class Class + { + void M() + { + new T(1); + } + } -internal class T -{ - private int v; + internal class T + { + private int v; - public T(int v) - { - this.v = v; - } -}", -index: 1); + public T(int v) + { + this.v = v; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithTwoValueParameters() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M() - { - new [|T|](1, """"); - } -}", -@"class Class -{ - void M() - { - new T(1, """"); - } -} + """ + class Class + { + void M() + { + new [|T|](1, ""); + } + } + """, + """ + class Class + { + void M() + { + new T(1, ""); + } + } -internal class T -{ - private int v1; - private string v2; + internal class T + { + private int v1; + private string v2; - public T(int v1, string v2) - { - this.v1 = v1; - this.v2 = v2; - } -}", -index: 1); + public T(int v1, string v2) + { + this.v1 = v1; + this.v2 = v2; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithNullableParameter() { await TestInRegularAndScriptAsync( -@"#nullable enable -class Class -{ - void M() - { - string? s = null; - new [|T|](s); - } -}", -@"#nullable enable -class Class -{ - void M() - { - string? s = null; - new [|T|](s); - } -} + """ + #nullable enable + class Class + { + void M() + { + string? s = null; + new [|T|](s); + } + } + """, + """ + #nullable enable + class Class + { + void M() + { + string? s = null; + new [|T|](s); + } + } -internal class T -{ - private string? s; + internal class T + { + private string? s; - public T(string? s) - { - this.s = s; - } -}", -index: 1); + public T(string? s) + { + this.s = s; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithNullableParameterThatIsNotNull() { await TestInRegularAndScriptAsync( -@"#nullable enable -class Class -{ - void M() - { - string? s = ""asdf""; - new [|T|](s); - } -}", -@"#nullable enable -class Class -{ - void M() - { - string? s = ""asdf""; - new [|T|](s); - } -} + """ + #nullable enable + class Class + { + void M() + { + string? s = "asdf"; + new [|T|](s); + } + } + """, + """ + #nullable enable + class Class + { + void M() + { + string? s = "asdf"; + new [|T|](s); + } + } -internal class T -{ - private string s; + internal class T + { + private string s; - public T(string s) - { - this.s = s; - } -}", -index: 1); + public T(string s) + { + this.s = s; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithNamedParameter() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M() - { - new [|T|](arg: 1); - } -}", -@"class Class -{ - void M() - { - new T(arg: 1); - } -} + """ + class Class + { + void M() + { + new [|T|](arg: 1); + } + } + """, + """ + class Class + { + void M() + { + new T(arg: 1); + } + } -internal class T -{ - private int arg; + internal class T + { + private int arg; - public T(int arg) - { - this.arg = arg; - } -}", -index: 1); + public T(int arg) + { + this.arg = arg; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithRefParameter() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - new [|T|](ref i); - } -}", -@"class Class -{ - void M(int i) - { - new T(ref i); - } -} + """ + class Class + { + void M(int i) + { + new [|T|](ref i); + } + } + """, + """ + class Class + { + void M(int i) + { + new T(ref i); + } + } -internal class T -{ - private int i; + internal class T + { + private int i; - public T(ref int i) - { - this.i = i; - } -}", -index: 1); + public T(ref int i) + { + this.i = i; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithOutParameter() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i, bool b) - { - new [|T|](out i, ref b, null); - } -}", -@"class Class -{ - void M(int i, bool b) - { - new T(out i, ref b, null); - } -} + """ + class Class + { + void M(int i, bool b) + { + new [|T|](out i, ref b, null); + } + } + """, + """ + class Class + { + void M(int i, bool b) + { + new T(out i, ref b, null); + } + } -internal class T -{ - private bool b; - private object value; + internal class T + { + private bool b; + private object value; - public T(out int i, ref bool b, object value) - { - i = 0; - this.b = b; - this.value = value; - } -}", -index: 1); + public T(out int i, ref bool b, object value) + { + i = 0; + this.b = b; + this.value = value; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithOutParameters1() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(string s) - { - new [|T|](out s); - } -}", -@"class Class -{ - void M(string s) - { - new T(out s); - } -} + """ + class Class + { + void M(string s) + { + new [|T|](out s); + } + } + """, + """ + class Class + { + void M(string s) + { + new T(out s); + } + } -internal class T -{ - public T(out string s) - { - s = null; - } -}", -index: 1); + internal class T + { + public T(out string s) + { + s = null; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithOutParameters2_CSharp7() { await TestInRegularAndScriptAsync( -@"using System; + """ + using System; -class Class -{ - void M(DateTime d) - { - new [|T|](out d); - } -}", -@"using System; + class Class + { + void M(DateTime d) + { + new [|T|](out d); + } + } + """, + """ + using System; -class Class -{ - void M(DateTime d) - { - new T(out d); - } -} + class Class + { + void M(DateTime d) + { + new T(out d); + } + } -internal class T -{ - public T(out DateTime d) - { - d = default(DateTime); - } -}", -index: 1, -parseOptions: TestOptions.Regular7); + internal class T + { + public T(out DateTime d) + { + d = default(DateTime); + } + } + """, + index: 1, + parseOptions: TestOptions.Regular7); } [Fact] public async Task GenerateWithOutParameters2() { await TestInRegularAndScriptAsync( -@"using System; + """ + using System; -class Class -{ - void M(DateTime d) - { - new [|T|](out d); - } -}", -@"using System; + class Class + { + void M(DateTime d) + { + new [|T|](out d); + } + } + """, + """ + using System; -class Class -{ - void M(DateTime d) - { - new T(out d); - } -} + class Class + { + void M(DateTime d) + { + new T(out d); + } + } -internal class T -{ - public T(out DateTime d) - { - d = default; - } -}", -index: 1); + internal class T + { + public T(out DateTime d) + { + d = default; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithOutParameters3() { await TestInRegularAndScriptAsync( -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class Class -{ - void M(IList d) - { - new [|T|](out d); - } -}", -@"using System.Collections.Generic; + class Class + { + void M(IList d) + { + new [|T|](out d); + } + } + """, + """ + using System.Collections.Generic; -class Class -{ - void M(IList d) - { - new T(out d); - } -} + class Class + { + void M(IList d) + { + new T(out d); + } + } -internal class T -{ - public T(out IList d) - { - d = null; - } -}", -index: 1); + internal class T + { + public T(out IList d) + { + d = null; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithOutParameters4() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int? d) - { - new [|T|](out d); - } -}", -@"class Class -{ - void M(int? d) - { - new T(out d); - } -} + """ + class Class + { + void M(int? d) + { + new [|T|](out d); + } + } + """, + """ + class Class + { + void M(int? d) + { + new T(out d); + } + } -internal class T -{ - public T(out int? d) - { - d = null; - } -}", -index: 1); + internal class T + { + public T(out int? d) + { + d = null; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithOutParameters5() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(X d) - { - new [|T|](out d); - } -}", -@"class Class -{ - void M(X d) - { - new T(out d); - } -} + """ + class Class + { + void M(X d) + { + new [|T|](out d); + } + } + """, + """ + class Class + { + void M(X d) + { + new T(out d); + } + } -internal class T -{ - public T(out object d) - { - d = null; - } -}", -index: 1); + internal class T + { + public T(out object d) + { + d = null; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithOutParameters6_CSharp7() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(X d) - { - new [|T|](out d); - } -}", -@"class Class -{ - void M(X d) - { - new T(out d); - } + """ + class Class + { + void M(X d) + { + new [|T|](out d); + } + } + """, + """ + class Class + { + void M(X d) + { + new T(out d); + } - private class T - { - public T(out X d) - { - d = default(X); - } - } -}", -index: 2, -parseOptions: TestOptions.Regular7); + private class T + { + public T(out X d) + { + d = default(X); + } + } + } + """, + index: 2, + parseOptions: TestOptions.Regular7); } [Fact] public async Task GenerateWithOutParameters6() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(X d) - { - new [|T|](out d); - } -}", -@"class Class -{ - void M(X d) - { - new T(out d); - } + """ + class Class + { + void M(X d) + { + new [|T|](out d); + } + } + """, + """ + class Class + { + void M(X d) + { + new T(out d); + } - private class T - { - public T(out X d) - { - d = default; - } - } -}", -index: 2); + private class T + { + public T(out X d) + { + d = default; + } + } + } + """, + index: 2); } [Fact] public async Task GenerateWithOutParameters7() { await TestInRegularAndScriptAsync( -@"class Class where X : class -{ - void M(X d) - { - new [|T|](out d); - } -}", -@"class Class where X : class -{ - void M(X d) - { - new T(out d); - } -} + """ + class Class where X : class + { + void M(X d) + { + new [|T|](out d); + } + } + """, + """ + class Class where X : class + { + void M(X d) + { + new T(out d); + } + } -internal class T -{ - public T(out object d) - { - d = null; - } -}", -index: 1); + internal class T + { + public T(out object d) + { + d = null; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithOutParameters8() { await TestInRegularAndScriptAsync( -@"class Class where X : class -{ - void M(X d) - { - new [|T|](out d); - } -}", -@"class Class where X : class -{ - void M(X d) - { - new T(out d); - } + """ + class Class where X : class + { + void M(X d) + { + new [|T|](out d); + } + } + """, + """ + class Class where X : class + { + void M(X d) + { + new T(out d); + } - private class T - { - public T(out X d) - { - d = null; - } - } -}", -index: 2); + private class T + { + public T(out X d) + { + d = null; + } + } + } + """, + index: 2); } [Fact] public async Task GenerateWithMethod() { await TestInRegularAndScriptAsync( -@"class Class -{ - string M(int i) - { - new [|T|](M); - } -}", -@"using System; + """ + class Class + { + string M(int i) + { + new [|T|](M); + } + } + """, + """ + using System; -class Class -{ - string M(int i) - { - new T(M); - } -} + class Class + { + string M(int i) + { + new T(M); + } + } -internal class T -{ - private Func m; + internal class T + { + private Func m; - public T(Func m) - { - this.m = m; - } -}", -index: 1); + public T(Func m) + { + this.m = m; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithLambda() { await TestInRegularAndScriptAsync( -@"class Class -{ - string M(int i) - { - new [|T|](a => a.ToString()); - } -}", -@"using System; + """ + class Class + { + string M(int i) + { + new [|T|](a => a.ToString()); + } + } + """, + """ + using System; -class Class -{ - string M(int i) - { - new T(a => a.ToString()); - } -} + class Class + { + string M(int i) + { + new T(a => a.ToString()); + } + } -internal class T -{ - private Func value; + internal class T + { + private Func value; - public T(Func value) - { - this.value = value; - } -}", -index: 1); + public T(Func value) + { + this.value = value; + } + } + """, + index: 1); } [Fact] public async Task GenerateWithDelegatingConstructor1() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](1); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](1); + } + } -class Base -{ - protected Base(int i) - { - } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(1); - } -} + class Base + { + protected Base(int i) + { + } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(1); + } + } -internal class T : Base -{ - public T(int i) : base(i) - { - } -} + internal class T : Base + { + public T(int i) : base(i) + { + } + } -class Base -{ - protected Base(int i) - { - } -}", -index: 1); + class Base + { + protected Base(int i) + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithDelegatingConstructor2() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](1); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](1); + } + } -class Base -{ - protected Base(object i) - { - } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(1); - } -} + class Base + { + protected Base(object i) + { + } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(1); + } + } -internal class T : Base -{ - public T(object i) : base(i) - { - } -} + internal class T : Base + { + public T(object i) : base(i) + { + } + } -class Base -{ - protected Base(object i) - { - } -}", -index: 1); + class Base + { + protected Base(object i) + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithDelegatingConstructor3() { await TestInRegularAndScriptAsync( -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -class Class -{ - void M() - { - Base b = new [|T|](new List()); - } -} + class Class + { + void M() + { + Base b = new [|T|](new List()); + } + } -class Base -{ - protected Base(IEnumerable values) - { - } -}", -@"using System.Collections.Generic; + class Base + { + protected Base(IEnumerable values) + { + } + } + """, + """ + using System.Collections.Generic; -class Class -{ - void M() - { - Base b = new T(new List()); - } -} + class Class + { + void M() + { + Base b = new T(new List()); + } + } -internal class T : Base -{ - public T(IEnumerable values) : base(values) - { - } -} + internal class T : Base + { + public T(IEnumerable values) : base(values) + { + } + } -class Base -{ - protected Base(IEnumerable values) - { - } -}", -index: 1); + class Base + { + protected Base(IEnumerable values) + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithDelegatingConstructor4() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](ref i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](ref i); + } + } -class Base -{ - protected Base(ref int o) - { - } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(ref i); - } -} + class Base + { + protected Base(ref int o) + { + } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(ref i); + } + } -internal class T : Base -{ - public T(ref int o) : base(ref o) - { - } -} + internal class T : Base + { + public T(ref int o) : base(ref o) + { + } + } -class Base -{ - protected Base(ref int o) - { - } -}", -index: 1); + class Base + { + protected Base(ref int o) + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithDelegatingConstructor5() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](a => a.ToString()); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](a => a.ToString()); + } + } -class Base -{ - protected Base(System.Func f) - { - } -}", -@"using System; + class Base + { + protected Base(System.Func f) + { + } + } + """, + """ + using System; -class Class -{ - void M(int i) - { - Base b = new T(a => a.ToString()); - } -} + class Class + { + void M(int i) + { + Base b = new T(a => a.ToString()); + } + } -internal class T : Base -{ - public T(Func f) : base(f) - { - } -} + internal class T : Base + { + public T(Func f) : base(f) + { + } + } -class Base -{ - protected Base(System.Func f) - { - } -}", -index: 1); + class Base + { + protected Base(System.Func f) + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithDelegatingConstructor6() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](out i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](out i); + } + } -class Base -{ - protected Base(out int o) - { - } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(out i); - } -} + class Base + { + protected Base(out int o) + { + } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(out i); + } + } -internal class T : Base -{ - public T(out int o) : base(out o) - { - } -} + internal class T : Base + { + public T(out int o) : base(out o) + { + } + } -class Base -{ - protected Base(out int o) - { - } -}", -index: 1); + class Base + { + protected Base(out int o) + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithDelegatingConstructorAssigningToNullableField() { await TestInRegularAndScriptAsync( -@"#nullable enable -class Class -{ - void M() - { - Base? b = new [|T|](); - } -} + """ + #nullable enable + class Class + { + void M() + { + Base? b = new [|T|](); + } + } -class Base -{ -}", -@"#nullable enable -class Class -{ - void M() - { - Base? b = new [|T|](); - } -} + class Base + { + } + """, + """ + #nullable enable + class Class + { + void M() + { + Base? b = new [|T|](); + } + } -internal class T : Base -{ -} + internal class T : Base + { + } -class Base -{ -}", -index: 1); + class Base + { + } + """, + index: 1); } [Fact] public async Task GenerateWithNonDelegatingConstructor1() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](1); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](1); + } + } -class Base -{ - protected Base(string i) - { - } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(1); - } -} + class Base + { + protected Base(string i) + { + } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(1); + } + } -internal class T : Base -{ - private int v; + internal class T : Base + { + private int v; - public T(int v) - { - this.v = v; - } -} + public T(int v) + { + this.v = v; + } + } -class Base -{ - protected Base(string i) - { - } -}", -index: 1); + class Base + { + protected Base(string i) + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithNonDelegatingConstructor2() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](ref i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](ref i); + } + } -class Base -{ - protected Base(out int o) - { - } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(ref i); - } -} + class Base + { + protected Base(out int o) + { + } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(ref i); + } + } -internal class T : Base -{ - private int i; + internal class T : Base + { + private int i; - public T(ref int i) - { - this.i = i; - } -} + public T(ref int i) + { + this.i = i; + } + } -class Base -{ - protected Base(out int o) - { - } -}", -index: 1); + class Base + { + protected Base(out int o) + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithNonDelegatingConstructor3() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i, bool f) - { - Base b = new [|T|](out i, out f); - } -} + """ + class Class + { + void M(int i, bool f) + { + Base b = new [|T|](out i, out f); + } + } -class Base -{ - protected Base(ref int o, out bool b) - { - } -}", -@"class Class -{ - void M(int i, bool f) - { - Base b = new T(out i, out f); - } -} + class Base + { + protected Base(ref int o, out bool b) + { + } + } + """, + """ + class Class + { + void M(int i, bool f) + { + Base b = new T(out i, out f); + } + } -internal class T : Base -{ - public T(out int i, out bool f) - { - i = 0; - f = false; - } -} + internal class T : Base + { + public T(out int i, out bool f) + { + i = 0; + f = false; + } + } -class Base -{ - protected Base(ref int o, out bool b) - { - } -}", -index: 1); + class Base + { + protected Base(ref int o, out bool b) + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithNonDelegatingConstructor4() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M() - { - Base b = new [|T|](1); - } -} + """ + class Class + { + void M() + { + Base b = new [|T|](1); + } + } -class Base -{ - private Base(int i) - { - } -}", -@"class Class -{ - void M() - { - Base b = new T(1); - } -} + class Base + { + private Base(int i) + { + } + } + """, + """ + class Class + { + void M() + { + Base b = new T(1); + } + } -internal class T : Base -{ - private int v; + internal class T : Base + { + private int v; - public T(int v) - { - this.v = v; - } -} + public T(int v) + { + this.v = v; + } + } -class Base -{ - private Base(int i) - { - } -}", -index: 1); + class Base + { + private Base(int i) + { + } + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToField1() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](i); + } + } -class Base -{ - protected int i; -}", -@"class Class -{ - void M(int i) - { - Base b = new T(i); - } -} + class Base + { + protected int i; + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - public T(int i) - { - this.i = i; - } -} + internal class T : Base + { + public T(int i) + { + this.i = i; + } + } -class Base -{ - protected int i; -}", -index: 1); + class Base + { + protected int i; + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToField2() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(string i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(string i) + { + Base b = new [|T|](i); + } + } -class Base -{ - protected object i; -}", -@"class Class -{ - void M(string i) - { - Base b = new T(i); - } -} + class Base + { + protected object i; + } + """, + """ + class Class + { + void M(string i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - public T(string i) - { - this.i = i; - } -} + internal class T : Base + { + public T(string i) + { + this.i = i; + } + } -class Base -{ - protected object i; -}", -index: 1); + class Base + { + protected object i; + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToField3() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(string i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(string i) + { + Base b = new [|T|](i); + } + } -class Base -{ - protected bool i; -}", -@"class Class -{ - void M(string i) - { - Base b = new T(i); - } -} + class Base + { + protected bool i; + } + """, + """ + class Class + { + void M(string i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - private string i; + internal class T : Base + { + private string i; - public T(string i) - { - this.i = i; - } -} + public T(string i) + { + this.i = i; + } + } -class Base -{ - protected bool i; -}", -index: 1); + class Base + { + protected bool i; + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToField4() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(bool i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(bool i) + { + Base b = new [|T|](i); + } + } -class Base -{ - protected bool ii; -}", -@"class Class -{ - void M(bool i) - { - Base b = new T(i); - } -} + class Base + { + protected bool ii; + } + """, + """ + class Class + { + void M(bool i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - private bool i; + internal class T : Base + { + private bool i; - public T(bool i) - { - this.i = i; - } -} + public T(bool i) + { + this.i = i; + } + } -class Base -{ - protected bool ii; -}", -index: 1); + class Base + { + protected bool ii; + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToField5() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(bool i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(bool i) + { + Base b = new [|T|](i); + } + } -class Base -{ - private bool i; -}", -@"class Class -{ - void M(bool i) - { - Base b = new T(i); - } -} + class Base + { + private bool i; + } + """, + """ + class Class + { + void M(bool i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - private bool i; + internal class T : Base + { + private bool i; - public T(bool i) - { - this.i = i; - } -} + public T(bool i) + { + this.i = i; + } + } -class Base -{ - private bool i; -}", -index: 1); + class Base + { + private bool i; + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToField6() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(bool i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(bool i) + { + Base b = new [|T|](i); + } + } -class Base -{ - protected readonly bool i; -}", -@"class Class -{ - void M(bool i) - { - Base b = new T(i); - } -} + class Base + { + protected readonly bool i; + } + """, + """ + class Class + { + void M(bool i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - private bool i; + internal class T : Base + { + private bool i; - public T(bool i) - { - this.i = i; - } -} + public T(bool i) + { + this.i = i; + } + } -class Base -{ - protected readonly bool i; -}", -index: 1); + class Base + { + protected readonly bool i; + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToField7() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](i); + } + } -class Base -{ - protected int I; -}", -@"class Class -{ - void M(int i) - { - Base b = new T(i); - } -} + class Base + { + protected int I; + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - public T(int i) - { - I = i; - } -} + internal class T : Base + { + public T(int i) + { + I = i; + } + } -class Base -{ - protected int I; -}", -index: 1); + class Base + { + protected int I; + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToField7WithQualification() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](i); + } + } -class Base -{ - protected int I; -}", -@"class Class -{ - void M(int i) - { - Base b = new T(i); - } -} + class Base + { + protected int I; + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - public T(int i) - { - this.I = i; - } -} + internal class T : Base + { + public T(int i) + { + this.I = i; + } + } -class Base -{ - protected int I; -}", -index: 1, -options: Option(CodeStyleOptions2.QualifyFieldAccess, true, NotificationOption2.Error)); + class Base + { + protected int I; + } + """, + index: 1, + options: Option(CodeStyleOptions2.QualifyFieldAccess, true, NotificationOption2.Error)); } [Fact] public async Task GenerateWithCallToField8() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](i); - } -} - -class Base -{ - private int I; -}", -@"class Class -{ - void M(int i) - { - Base b = new T(i); - } -} - -internal class T : Base -{ - private int i; + """ + class Class + { + void M(int i) + { + Base b = new [|T|](i); + } + } - public T(int i) - { - this.i = i; - } -} + class Base + { + private int I; + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(i); + } + } -class Base -{ - private int I; -}", -index: 1); - } + internal class T : Base + { + private int i; - [Fact] - public async Task GenerateWithCallToField9() - { - await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](i); - } -} + public T(int i) + { + this.i = i; + } + } -class Base -{ - public static int i; -}", -@"class Class -{ - void M(int i) - { - Base b = new T(i); + class Base + { + private int I; + } + """, + index: 1); } -} - -internal class T : Base -{ - private int i; - public T(int i) + [Fact] + public async Task GenerateWithCallToField9() { - this.i = i; - } -} + await TestInRegularAndScriptAsync( + """ + class Class + { + void M(int i) + { + Base b = new [|T|](i); + } + } -class Base -{ - public static int i; -}", -index: 1); + class Base + { + public static int i; + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(i); + } + } + + internal class T : Base + { + private int i; + + public T(int i) + { + this.i = i; + } + } + + class Base + { + public static int i; + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToField10() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - D d = new [|T|](i); - } -} + """ + class Class + { + void M(int i) + { + D d = new [|T|](i); + } + } -class D : B -{ - protected int I; -} + class D : B + { + protected int I; + } -class B -{ - protected int i }", -@"class Class -{ - void M(int i) - { - D d = new T(i); - } -} + class B + { + protected int i } + """, + """ + class Class + { + void M(int i) + { + D d = new T(i); + } + } -internal class T : D -{ - public T(int i) - { - this.i = i; - } -} + internal class T : D + { + public T(int i) + { + this.i = i; + } + } -class D : B -{ - protected int I; -} + class D : B + { + protected int I; + } -class B -{ - protected int i }", -index: 1); + class B + { + protected int i } + """, + index: 1); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49924")] @@ -2907,260 +3275,288 @@ public async Task GenerateCorrectFieldNaming() var options = new NamingStylesTestOptionSets(LanguageNames.CSharp); await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - D d = new [|D|](i); - } -}", -@"class Class -{ - void M(int i) - { - D d = new D(i); - } -} + """ + class Class + { + void M(int i) + { + D d = new [|D|](i); + } + } + """, + """ + class Class + { + void M(int i) + { + D d = new D(i); + } + } -internal class D -{ - private int _i; + internal class D + { + private int _i; - public D(int i) - { - _i = i; - } -}", -index: 1, options: options.FieldNamesAreCamelCaseWithUnderscorePrefix); + public D(int i) + { + _i = i; + } + } + """, + index: 1, options: options.FieldNamesAreCamelCaseWithUnderscorePrefix); } [Fact] public async Task GenerateWithCallToProperty1() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](i); + } + } -class Base -{ - public int I { get; private set; } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(i); - } -} + class Base + { + public int I { get; private set; } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - private int i; + internal class T : Base + { + private int i; - public T(int i) - { - this.i = i; - } -} + public T(int i) + { + this.i = i; + } + } -class Base -{ - public int I { get; private set; } -}", -index: 1); + class Base + { + public int I { get; private set; } + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToProperty2() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](i); + } + } -class Base -{ - public int I { get; protected set; } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(i); - } -} + class Base + { + public int I { get; protected set; } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - public T(int i) - { - I = i; - } -} + internal class T : Base + { + public T(int i) + { + I = i; + } + } -class Base -{ - public int I { get; protected set; } -}", -index: 1); + class Base + { + public int I { get; protected set; } + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToProperty2WithQualification() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](i); + } + } -class Base -{ - public int I { get; protected set; } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(i); - } -} + class Base + { + public int I { get; protected set; } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - public T(int i) - { - this.I = i; - } -} + internal class T : Base + { + public T(int i) + { + this.I = i; + } + } -class Base -{ - public int I { get; protected set; } -}", -index: 1, -options: Option(CodeStyleOptions2.QualifyPropertyAccess, true, NotificationOption2.Error)); + class Base + { + public int I { get; protected set; } + } + """, + index: 1, + options: Option(CodeStyleOptions2.QualifyPropertyAccess, true, NotificationOption2.Error)); } [Fact] public async Task GenerateWithCallToProperty3() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](i); + } + } -class Base -{ - protected int I { get; set; } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(i); - } -} + class Base + { + protected int I { get; set; } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - public T(int i) - { - I = i; - } -} + internal class T : Base + { + public T(int i) + { + I = i; + } + } -class Base -{ - protected int I { get; set; } -}", -index: 1); + class Base + { + protected int I { get; set; } + } + """, + index: 1); } [Fact] public async Task GenerateWithCallToProperty3WithQualification() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - Base b = new [|T|](i); - } -} + """ + class Class + { + void M(int i) + { + Base b = new [|T|](i); + } + } -class Base -{ - protected int I { get; set; } -}", -@"class Class -{ - void M(int i) - { - Base b = new T(i); - } -} + class Base + { + protected int I { get; set; } + } + """, + """ + class Class + { + void M(int i) + { + Base b = new T(i); + } + } -internal class T : Base -{ - public T(int i) - { - this.I = i; - } -} + internal class T : Base + { + public T(int i) + { + this.I = i; + } + } -class Base -{ - protected int I { get; set; } -}", -index: 1, -options: Option(CodeStyleOptions2.QualifyPropertyAccess, true, NotificationOption2.Error)); + class Base + { + protected int I { get; set; } + } + """, + index: 1, + options: Option(CodeStyleOptions2.QualifyPropertyAccess, true, NotificationOption2.Error)); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/942568")] public async Task GenerateTypeWithPreferIntrinsicPredefinedKeywordFalse() { - await TestInRegularAndScriptAsync( -@"class Class { - void M(int i) - { - var b = new [|T|](i); - } -}", -@"class Class { - void M(int i) - { - var b = new T(i); - } -} + await TestInRegularAndScriptAsync( + """ + class Class { + void M(int i) + { + var b = new [|T|](i); + } + } + """, + """ + class Class { + void M(int i) + { + var b = new T(i); + } + } -internal class T -{ - private System.Int32 i; + internal class T + { + private System.Int32 i; - public T(System.Int32 i) - { - this.i = i; - } -}", -index: 1, -options: Option(CodeStyleOptions2.PreferIntrinsicPredefinedTypeKeywordInDeclaration, false, NotificationOption2.Error)); + public T(System.Int32 i) + { + this.i = i; + } + } + """, + index: 1, + options: Option(CodeStyleOptions2.PreferIntrinsicPredefinedTypeKeywordInDeclaration, false, NotificationOption2.Error)); } #endregion @@ -3171,113 +3567,139 @@ public T(System.Int32 i) public async Task TestGenerateInterfaceFromTypeConstraint() { await TestInRegularAndScriptAsync( -@"class EmployeeList where T : Employee, [|IEmployee|], new() -{ -}", -@"class EmployeeList where T : Employee, IEmployee, new() -{ -} + """ + class EmployeeList where T : Employee, [|IEmployee|], new() + { + } + """, + """ + class EmployeeList where T : Employee, IEmployee, new() + { + } -internal interface IEmployee -{ -}", -index: 1); + internal interface IEmployee + { + } + """, + index: 1); } [Fact] public async Task TestGenerateInterfaceFromTypeConstraints() { await TestInRegularAndScriptAsync( -@"class EmployeeList where T : Employee, IEmployee, [|IComparable|], new() -{ -}", -@"class EmployeeList where T : Employee, IEmployee, IComparable, new() -{ -} + """ + class EmployeeList where T : Employee, IEmployee, [|IComparable|], new() + { + } + """, + """ + class EmployeeList where T : Employee, IEmployee, IComparable, new() + { + } -internal interface IComparable where T : Employee, IEmployee, IComparable, new() -{ -}", -index: 1); + internal interface IComparable where T : Employee, IEmployee, IComparable, new() + { + } + """, + index: 1); } [Fact] public async Task NegativeTestGenerateInterfaceFromTypeConstraint() { await TestMissingInRegularAndScriptAsync( -@"using System; + """ + using System; -class EmployeeList where T : Employee, IEmployee, [|IComparable|], new() -{ -}"); + class EmployeeList where T : Employee, IEmployee, [|IComparable|], new() + { + } + """); } [Fact] public async Task TestGenerateInterfaceFromBaseList1() { await TestInRegularAndScriptAsync( -@"interface A : [|B|] -{ -}", -@"interface A : B -{ -} + """ + interface A : [|B|] + { + } + """, + """ + interface A : B + { + } -internal interface B -{ -}", -index: 1); + internal interface B + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538519")] public async Task TestGenerateInterfaceFromBaseList2() { await TestInRegularAndScriptAsync( -@"class Test : [|ITest|] -{ -}", -@"class Test : ITest -{ -} + """ + class Test : [|ITest|] + { + } + """, + """ + class Test : ITest + { + } -internal interface ITest -{ -}", -index: 1); + internal interface ITest + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538519")] public async Task TestGenerateInterfaceFromTypeConstraints2() { await TestInRegularAndScriptAsync( -@"class Test where T : [|ITest|] -{ -}", -@"class Test where T : ITest -{ -} + """ + class Test where T : [|ITest|] + { + } + """, + """ + class Test where T : ITest + { + } -internal interface ITest -{ -}", -index: 1); + internal interface ITest + { + } + """, + index: 1); } [Fact] public async Task TestGenerateInterfaceFromBaseList3() { await TestInRegularAndScriptAsync( -@"class A : object, [|B|] -{ -}", -@"class A : object, B -{ -} + """ + class A : object, [|B|] + { + } + """, + """ + class A : object, B + { + } -internal interface B -{ -}", -index: 1); + internal interface B + { + } + """, + index: 1); } #endregion @@ -3286,510 +3708,572 @@ internal interface B public async Task NotInLeftSideOfAssignment() { await TestMissingInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - [|Goo|] = 2; - } -}"); + """ + class Class + { + void M(int i) + { + [|Goo|] = 2; + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539339")] public async Task InLeftSideOfAssignment() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - [|Goo|].Bar = 2; - } -}", -@"class Class -{ - void M(int i) - { - Goo.Bar = 2; - } -} + """ + class Class + { + void M(int i) + { + [|Goo|].Bar = 2; + } + } + """, + """ + class Class + { + void M(int i) + { + Goo.Bar = 2; + } + } -internal class Goo -{ -}", -index: 1); + internal class Goo + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539339")] public async Task NotInRightSideOfAssignment() { await TestMissingInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - x = [|Goo|]; - } -}"); + """ + class Class + { + void M(int i) + { + x = [|Goo|]; + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539339")] public async Task InRightSideOfAssignment() { await TestInRegularAndScriptAsync( -@"class Class -{ - void M(int i) - { - x = [|Goo|].Bar; - } -}", -@"class Class -{ - void M(int i) - { - x = Goo.Bar; - } -} + """ + class Class + { + void M(int i) + { + x = [|Goo|].Bar; + } + } + """, + """ + class Class + { + void M(int i) + { + x = Goo.Bar; + } + } -internal class Goo -{ -}", -index: 1); + internal class Goo + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539489")] public async Task TestEscapedName() { await TestInRegularAndScriptAsync( -@"class Class -{ - [|@Goo|] f; -}", -@"class Class -{ - @Goo f; -} + """ + class Class + { + [|@Goo|] f; + } + """, + """ + class Class + { + @Goo f; + } -internal class Goo -{ -}", -index: 1); + internal class Goo + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539489")] public async Task TestEscapedKeyword() { await TestInRegularAndScriptAsync( -@"class Class -{ - [|@int|] f; -}", -@"class Class -{ - @int f; -} + """ + class Class + { + [|@int|] f; + } + """, + """ + class Class + { + @int f; + } -internal class @int -{ -}", -index: 1); + internal class @int + { + } + """, + index: 1); } [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539535")] public async Task TestGenerateIntoNewFile() { await TestAddDocumentInRegularAndScriptAsync( -@"class Class { void F() { new [|Goo|].Bar(); } }", -@"namespace Goo -{ - internal class Bar - { - public Bar() - { - } - } -}", -expectedContainers: ImmutableArray.Create("Goo"), -expectedDocumentName: "Bar.cs"); + @"class Class { void F() { new [|Goo|].Bar(); } }", + """ + namespace Goo + { + internal class Bar + { + public Bar() + { + } + } + } + """, + expectedContainers: ImmutableArray.Create("Goo"), + expectedDocumentName: "Bar.cs"); } [WpfFact] public async Task TestGenerateIntoNewFileWithUsings1() { await TestAddDocumentInRegularAndScriptAsync( -@"class Class { void F() { new [|Goo|].Bar(new System.Collections.Generic.List()); } }", -@"using System.Collections.Generic; + @"class Class { void F() { new [|Goo|].Bar(new System.Collections.Generic.List()); } }", + """ + using System.Collections.Generic; -namespace Goo -{ - internal class Bar - { - private List list; + namespace Goo + { + internal class Bar + { + private List list; - public Bar(List list) - { - this.list = list; - } - } -}", -expectedContainers: ImmutableArray.Create("Goo"), -expectedDocumentName: "Bar.cs"); + public Bar(List list) + { + this.list = list; + } + } + } + """, + expectedContainers: ImmutableArray.Create("Goo"), + expectedDocumentName: "Bar.cs"); } [WpfFact] public async Task TestGenerateIntoNewFileWithUsings2() { await TestAddDocumentInRegularAndScriptAsync( -@"class Class { void F() { new [|Goo|].Bar(new System.Collections.Generic.List()); } }", -@"namespace Goo -{ - using System.Collections.Generic; + @"class Class { void F() { new [|Goo|].Bar(new System.Collections.Generic.List()); } }", + """ + namespace Goo + { + using System.Collections.Generic; - internal class Bar - { - private List list; + internal class Bar + { + private List list; - public Bar(List list) - { - this.list = list; - } - } -}", -expectedContainers: ImmutableArray.Create("Goo"), -expectedDocumentName: "Bar.cs", -parameters: new TestParameters(options: Option(CSharpCodeStyleOptions.PreferredUsingDirectivePlacement, AddImportPlacement.InsideNamespace, NotificationOption2.Error))); + public Bar(List list) + { + this.list = list; + } + } + } + """, + expectedContainers: ImmutableArray.Create("Goo"), + expectedDocumentName: "Bar.cs", + parameters: new TestParameters(options: Option(CSharpCodeStyleOptions.PreferredUsingDirectivePlacement, AddImportPlacement.InsideNamespace, NotificationOption2.Error))); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539620")] public async Task TestDeclarationSpan() { await TestSpansAsync( -@"class Class -{ - void Goo() - { - [|Bar|] b; - } -}"); + """ + class Class + { + void Goo() + { + [|Bar|] b; + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539674")] public async Task TestNotInEnumBaseList() { await TestMissingInRegularAndScriptAsync( -@"enum E : [|A|] -{ -}"); + """ + enum E : [|A|] + { + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539681")] public async Task TestNotInConditional() { await TestMissingInRegularAndScriptAsync( -@"class Program -{ - static void Main(string[] args) - { - if ([|IsTrue|]) - { - } - } -}"); + """ + class Program + { + static void Main(string[] args) + { + if ([|IsTrue|]) + { + } + } + } + """); } [Fact] public async Task TestInUsing() { await TestInRegularAndScriptAsync( -@"using System; -using System.Collections.Generic; -using System.Linq; + """ + using System; + using System.Collections.Generic; + using System.Linq; -class Program -{ - static void Main(string[] args) - { - using ([|Goo|] f = bar()) - { - } - } -}", -@"using System; -using System.Collections.Generic; -using System.Linq; + class Program + { + static void Main(string[] args) + { + using ([|Goo|] f = bar()) + { + } + } + } + """, + """ + using System; + using System.Collections.Generic; + using System.Linq; -class Program -{ - static void Main(string[] args) - { - using (Goo f = bar()) - { - } - } -} + class Program + { + static void Main(string[] args) + { + using (Goo f = bar()) + { + } + } + } -internal class Goo -{ -}", -index: 1); + internal class Goo + { + } + """, + index: 1); } [Fact, WorkItem("https://github.com/dotnet/roslyn/pull/54493")] public async Task TestInLocalFunction() { await TestInRegularAndScriptAsync( -@"using System; + """ + using System; -class Program -{ - static void Main(string[] args) - { - static [|Goo|] - } -}", -@"using System; + class Program + { + static void Main(string[] args) + { + static [|Goo|] + } + } + """, + """ + using System; -class Program -{ - static void Main(string[] args) - { - static Goo - } -} + class Program + { + static void Main(string[] args) + { + static Goo + } + } -internal class Goo -{ -}", -index: 1); + internal class Goo + { + } + """, + index: 1); } [Fact] public async Task TestNotInDelegateConstructor() { await TestMissingInRegularAndScriptAsync( -@"delegate void D(int x); + """ + delegate void D(int x); -class C -{ - void M() - { - D d = new D([|Test|]); - } -}"); + class C + { + void M() + { + D d = new D([|Test|]); + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539754")] public async Task TestMissingOnVar() { await TestMissingInRegularAndScriptAsync( -@"using System; -using System.Collections.Generic; -using System.Linq; + """ + using System; + using System.Collections.Generic; + using System.Linq; -class Program -{ - static void Main(string[] args) - { - [|var|] x = new Program(); - } -}"); + class Program + { + static void Main(string[] args) + { + [|var|] x = new Program(); + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539765")] public async Task TestElideDefaultConstructor() { await TestInRegularAndScriptAsync( -@"class A -{ - void M() - { - C test = new [|B|](); - } -} + """ + class A + { + void M() + { + C test = new [|B|](); + } + } -internal class C -{ -}", -@"class A -{ - void M() - { - C test = new B(); - } -} + internal class C + { + } + """, + """ + class A + { + void M() + { + C test = new B(); + } + } -internal class B : C -{ -} + internal class B : C + { + } -internal class C -{ -}", -index: 1); + internal class C + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539783")] public async Task RegressionFor5867ErrorToleranceTopLevel() { await TestMissingAsync( -@"[|this|] . f = f ; ", -new TestParameters(GetScriptOptions())); + @"[|this|] . f = f ; ", + new TestParameters(GetScriptOptions())); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539799")] public async Task TestOnInaccessibleType() { await TestMissingInRegularAndScriptAsync( -@"class C -{ - private class D - { - } -} + """ + class C + { + private class D + { + } + } -class A -{ - void M() - { - C.[|D|] d = new C.D(); - } -}"); + class A + { + void M() + { + C.[|D|] d = new C.D(); + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539794")] public async Task TestDefaultConstructorInTypeDerivingFromInterface() { await TestInRegularAndScriptAsync( -@"class Program -{ - static void Main(string[] args) - { - I obj = new [|A|](); - } -} + """ + class Program + { + static void Main(string[] args) + { + I obj = new [|A|](); + } + } -interface I -{ -}", -@"class Program -{ - static void Main(string[] args) - { - I obj = new A(); - } -} + interface I + { + } + """, + """ + class Program + { + static void Main(string[] args) + { + I obj = new A(); + } + } -internal class A : I -{ -} + internal class A : I + { + } -interface I -{ -}", -index: 1); + interface I + { + } + """, + index: 1); } [Fact] public async Task TestGenerateWithThrow() { await TestInRegularAndScriptAsync( -@"using System; + """ + using System; -class C -{ - void M() - { - throw new [|NotFoundException|](); - } -}", -@"using System; -using System.Runtime.Serialization; + class C + { + void M() + { + throw new [|NotFoundException|](); + } + } + """, + """ + using System; + using System.Runtime.Serialization; -class C -{ - void M() - { - throw new NotFoundException(); - } -} + class C + { + void M() + { + throw new NotFoundException(); + } + } -[Serializable] -internal class NotFoundException : Exception -{ - public NotFoundException() - { - } + [Serializable] + internal class NotFoundException : Exception + { + public NotFoundException() + { + } - public NotFoundException(string message) : base(message) - { - } + public NotFoundException(string message) : base(message) + { + } - public NotFoundException(string message, Exception innerException) : base(message, innerException) - { - } + public NotFoundException(string message, Exception innerException) : base(message, innerException) + { + } - protected NotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } -}", -index: 1); + protected NotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } + """, + index: 1); } [Fact] public async Task TestGenerateInTryCatch() { await TestInRegularAndScriptAsync( -@"using System; + """ + using System; -class C -{ - void M() - { - try - { - } - catch ([|NotFoundException|] ex) - { - } - } -}", -@"using System; -using System.Runtime.Serialization; + class C + { + void M() + { + try + { + } + catch ([|NotFoundException|] ex) + { + } + } + } + """, + """ + using System; + using System.Runtime.Serialization; -class C -{ - void M() - { - try - { - } - catch (NotFoundException ex) - { - } - } -} + class C + { + void M() + { + try + { + } + catch (NotFoundException ex) + { + } + } + } -[Serializable] -internal class NotFoundException : Exception -{ - public NotFoundException() - { - } + [Serializable] + internal class NotFoundException : Exception + { + public NotFoundException() + { + } - public NotFoundException(string message) : base(message) - { - } + public NotFoundException(string message) : base(message) + { + } - public NotFoundException(string message, Exception innerException) : base(message, innerException) - { - } + public NotFoundException(string message, Exception innerException) : base(message, innerException) + { + } - protected NotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } -}", -index: 1); + protected NotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } + """, + index: 1); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)] @@ -3797,1027 +4281,1177 @@ protected NotFoundException(SerializationInfo info, StreamingContext context) : public async Task TestNotGenerateInDelegateConstructor() { await TestMissingInRegularAndScriptAsync( -@"using System; + """ + using System; -delegate void D(int x); + delegate void D(int x); -class C -{ - void M() - { - D d = new D([|Test|]); - } -}"); + class C + { + void M() + { + D d = new D([|Test|]); + } + } + """); } [Fact] public async Task TestInStructBaseList() { await TestInRegularAndScriptAsync( -@"struct S : [|A|] -{ -}", -@"struct S : A -{ -} + """ + struct S : [|A|] + { + } + """, + """ + struct S : A + { + } -internal interface A -{ -}", -index: 1); + internal interface A + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539870")] public async Task TestGenericWhenNonGenericExists() { await TestInRegularAndScriptAsync( -@"class C -{ - void Goo() - { - [|A|] a; - } -} + """ + class C + { + void Goo() + { + [|A|] a; + } + } -class A -{ -}", -@"class C -{ - void Goo() - { - A a; - } -} + class A + { + } + """, + """ + class C + { + void Goo() + { + A a; + } + } -internal class A -{ -} + internal class A + { + } -class A -{ -}", -index: 1); + class A + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539930")] public async Task TestInheritedTypeParameters() { await TestInRegularAndScriptAsync( -@"class C -{ - void M() - { - I i = new [|D|](); - } -} + """ + class C + { + void M() + { + I i = new [|D|](); + } + } -interface I -{ -}", -@"class C -{ - void M() - { - I i = new D(); - } -} + interface I + { + } + """, + """ + class C + { + void M() + { + I i = new D(); + } + } -internal class D : I -{ -} + internal class D : I + { + } -interface I -{ -}", -index: 1); + interface I + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539971")] public async Task TestDoNotUseOuterTypeParameters() { await TestInRegularAndScriptAsync( -@"class C -{ - public void Goo() - { - [|D|] d; - } -}", -@"class C -{ - public void Goo() - { - D d; - } + """ + class C + { + public void Goo() + { + [|D|] d; + } + } + """, + """ + class C + { + public void Goo() + { + D d; + } - private class D - { - } -}", -index: 2); + private class D + { + } + } + """, + index: 2); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539970")] public async Task TestReferencingTypeParameters1() { await TestInRegularAndScriptAsync( -@"class M -{ - public void Goo() - { - I i = new [|C|](); - } -} - -interface I -{ -}", -@"class M -{ - public void Goo() - { - I i = new C(); - } -} + """ + class M + { + public void Goo() + { + I i = new [|C|](); + } + } -internal class C : I -{ -} + interface I + { + } + """, + """ + class M + { + public void Goo() + { + I i = new C(); + } + } -interface I -{ -}", -index: 1); + internal class C : I + { + } + + interface I + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539970")] public async Task TestReferencingTypeParameters2() { await TestInRegularAndScriptAsync( -@"class M -{ - public void Goo() - { - I i = new [|C|](); - } -} + """ + class M + { + public void Goo() + { + I i = new [|C|](); + } + } -interface I -{ -}", -@"class M -{ - public void Goo() - { - I i = new C(); - } + interface I + { + } + """, + """ + class M + { + public void Goo() + { + I i = new C(); + } - private class C : I - { - } -} + private class C : I + { + } + } -interface I -{ -}", -index: 2); + interface I + { + } + """, + index: 2); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539972")] public async Task TestReferencingTypeParameters3() { await TestInRegularAndScriptAsync( -@"class C -{ - public void Goo(T1 t1, T2 t2) - { - A a = new [|A|](t1, t2); - } -}", -@"class C -{ - public void Goo(T1 t1, T2 t2) - { - A a = new A(t1, t2); - } -} + """ + class C + { + public void Goo(T1 t1, T2 t2) + { + A a = new [|A|](t1, t2); + } + } + """, + """ + class C + { + public void Goo(T1 t1, T2 t2) + { + A a = new A(t1, t2); + } + } -internal class A -{ - private object t1; - private object t2; + internal class A + { + private object t1; + private object t2; - public A(object t1, object t2) - { - this.t1 = t1; - this.t2 = t2; - } -}", -index: 1); + public A(object t1, object t2) + { + this.t1 = t1; + this.t2 = t2; + } + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539972")] public async Task TestReferencingTypeParameters4() { await TestInRegularAndScriptAsync( -@"class C -{ - public void Goo(T1 t1, T2 t2) - { - A a = new [|A|](t1, t2); - } -}", -@"class C -{ - public void Goo(T1 t1, T2 t2) - { - A a = new A(t1, t2); - } + """ + class C + { + public void Goo(T1 t1, T2 t2) + { + A a = new [|A|](t1, t2); + } + } + """, + """ + class C + { + public void Goo(T1 t1, T2 t2) + { + A a = new A(t1, t2); + } - private class A - { - private T1 t1; - private T2 t2; + private class A + { + private T1 t1; + private T2 t2; - public A(T1 t1, T2 t2) - { - this.t1 = t1; - this.t2 = t2; - } - } -}", -index: 2); + public A(T1 t1, T2 t2) + { + this.t1 = t1; + this.t2 = t2; + } + } + } + """, + index: 2); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539992")] public async Task TestNotPassingEmptyIssueListToCtor() { await TestMissingInRegularAndScriptAsync( -@"using System.Linq; + """ + using System.Linq; -class Program -{ - void Main() - { - Enumerable.[|T|] Enumerable . Select(Enumerable.Range(0, 9), i => char.Parse(i.ToString())) } -}"); + class Program + { + void Main() + { + Enumerable.[|T|] Enumerable . Select(Enumerable.Range(0, 9), i => char.Parse(i.ToString())) } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540644")] public async Task TestGenerateWithVoidArg() { await TestInRegularAndScriptAsync( -@"class Program -{ - void M() - { - C c = new [|C|](M()); - } -}", -@"class Program -{ - void M() - { - C c = new C(M()); - } -} + """ + class Program + { + void M() + { + C c = new [|C|](M()); + } + } + """, + """ + class Program + { + void M() + { + C c = new C(M()); + } + } -internal class C -{ - private object v; + internal class C + { + private object v; - public C(object v) - { - this.v = v; - } -}", -index: 1); + public C(object v) + { + this.v = v; + } + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540989")] public async Task TestMissingOnInaccessibleType() { await TestMissingInRegularAndScriptAsync( -@"class Outer -{ - class Inner - { - } -} + """ + class Outer + { + class Inner + { + } + } -class A -{ - Outer.[|Inner|] inner; -}"); + class A + { + Outer.[|Inner|] inner; + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540766")] public async Task TestOnInvalidGlobalCode() { await TestInRegularAndScriptAsync( -@"[|a|] test ", -@"[|a|] test internal class a -{ -}", -index: 1); + @"[|a|] test ", + """ + [|a|] test internal class a + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539985")] public async Task TestDoNotInferTypeWithWrongArity() { await TestInRegularAndScriptAsync( -@"class C -{ - public void Test() - { - C c = new [|C|](); - } -}", -@"class C -{ - public void Test() - { - C c = new C(); - } -} + """ + class C + { + public void Test() + { + C c = new [|C|](); + } + } + """, + """ + class C + { + public void Test() + { + C c = new C(); + } + } -internal class C -{ - public C() - { - } -}", -index: 1); + internal class C + { + public C() + { + } + } + """, + index: 1); } [Fact] public async Task TestMissingOnInvalidConstructorToExistingType() { await TestMissingInRegularAndScriptAsync( -@"class Program -{ - static void Main() - { - new [|Program|](1); - } -}"); + """ + class Program + { + static void Main() + { + new [|Program|](1); + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541263")] public async Task TestAccessibilityConstraint() { await TestInRegularAndScriptAsync( -@"public static class MyExtension -{ - public static int ExtensionMethod(this String s, [|D|] d) - { - return 10; - } -}", -@"public static class MyExtension -{ - public static int ExtensionMethod(this String s, D d) - { - return 10; - } -} + """ + public static class MyExtension + { + public static int ExtensionMethod(this String s, [|D|] d) + { + return 10; + } + } + """, + """ + public static class MyExtension + { + public static int ExtensionMethod(this String s, D d) + { + return 10; + } + } -public class D -{ -}", -index: 1); + public class D + { + } + """, + index: 1); } [Fact] public async Task TestBaseTypeAccessibilityConstraint() { await TestInRegularAndScriptAsync( -@"public class C : [|D|] -{ -}", -@"public class C : D -{ -} + """ + public class C : [|D|] + { + } + """, + """ + public class C : D + { + } -public class D -{ -}", -index: 1); + public class D + { + } + """, + index: 1); } [Fact] public async Task TestBaseInterfaceAccessibilityConstraint1() { await TestInRegularAndScriptAsync( -@"public class C : X, [|IGoo|] -{ -}", -@"public class C : X, IGoo -{ -} + """ + public class C : X, [|IGoo|] + { + } + """, + """ + public class C : X, IGoo + { + } -internal interface IGoo -{ -}", -index: 1); + internal interface IGoo + { + } + """, + index: 1); } [Fact] public async Task TestAccessibilityConstraint2() { await TestInRegularAndScriptAsync( -@"public interface C : [|IBar|], IGoo -{ -}", -@"public interface C : IBar, IGoo -{ -} + """ + public interface C : [|IBar|], IGoo + { + } + """, + """ + public interface C : IBar, IGoo + { + } -public interface IBar -{ -}", -index: 1); + public interface IBar + { + } + """, + index: 1); } [Fact] public async Task TestAccessibilityConstraint3() { await TestInRegularAndScriptAsync( -@"public interface C : IBar, [|IGoo|] -{ -}", -@"public interface C : IBar, IGoo -{ -} + """ + public interface C : IBar, [|IGoo|] + { + } + """, + """ + public interface C : IBar, IGoo + { + } -public interface IGoo -{ -}", -index: 1); + public interface IGoo + { + } + """, + index: 1); } [Fact] public async Task TestDelegateReturnTypeAccessibilityConstraint() { await TestInRegularAndScriptAsync( -@"public delegate [|D|] Goo();", -@"public delegate D Goo(); + @"public delegate [|D|] Goo();", + """ + public delegate D Goo(); -public class D -{ -}", -index: 1); + public class D + { + } + """, + index: 1); } [Fact] public async Task TestDelegateParameterAccessibilityConstraint() { await TestInRegularAndScriptAsync( -@"public delegate D Goo([|S|] d);", -@"public delegate D Goo(S d); + @"public delegate D Goo([|S|] d);", + """ + public delegate D Goo(S d); -public class S -{ -}", -index: 1); + public class S + { + } + """, + index: 1); } [Fact] public async Task TestMethodParameterAccessibilityConstraint() { await TestInRegularAndScriptAsync( -@"public class C -{ - public void Goo([|F|] f); -}", -@"public class C -{ - public void Goo(F f); -} + """ + public class C + { + public void Goo([|F|] f); + } + """, + """ + public class C + { + public void Goo(F f); + } -public class F -{ -}", -index: 1); + public class F + { + } + """, + index: 1); } [Fact] public async Task TestMethodReturnTypeAccessibilityConstraint() { await TestInRegularAndScriptAsync( -@"public class C -{ - public [|F|] Goo(Bar f); -}", -@"public class C -{ - public F Goo(Bar f); + """ + public class C + { + public [|F|] Goo(Bar f); + } + """, + """ + public class C + { + public F Goo(Bar f); - public class F - { - } -}", -index: 2); + public class F + { + } + } + """, + index: 2); } [Fact] public async Task TestPropertyTypeAccessibilityConstraint() { await TestInRegularAndScriptAsync( -@"public class C -{ - public [|F|] Goo { get; } -}", -@"public class C -{ - public F Goo { get; } + """ + public class C + { + public [|F|] Goo { get; } + } + """, + """ + public class C + { + public F Goo { get; } - public class F - { - } -}", -index: 2); + public class F + { + } + } + """, + index: 2); } [Fact] public async Task TestFieldEventTypeAccessibilityConstraint() { await TestInRegularAndScriptAsync( -@"public class C -{ - public event [|F|] E; -}", -@"public class C -{ - public event F E; + """ + public class C + { + public event [|F|] E; + } + """, + """ + public class C + { + public event F E; - public class F - { - } -}", -index: 2); + public class F + { + } + } + """, + index: 2); } [Fact] public async Task TestEventTypeAccessibilityConstraint() { await TestInRegularAndScriptAsync( -@"public class C -{ - public event [|F|] E - { - add - { - } + """ + public class C + { + public event [|F|] E + { + add + { + } - remove - { - } - } -}", -@"public class C -{ - public event F E - { - add - { - } + remove + { + } + } + } + """, + """ + public class C + { + public event F E + { + add + { + } - remove - { - } - } -} + remove + { + } + } + } -public class F -{ -}", -index: 1); + public class F + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541654")] public async Task TestGenerateVarType() { await TestInRegularAndScriptAsync( -@"class C -{ - public static void Main() - { - [|@var|] v; - } -}", -@"class C -{ - public static void Main() - { - @var v; - } -} + """ + class C + { + public static void Main() + { + [|@var|] v; + } + } + """, + """ + class C + { + public static void Main() + { + @var v; + } + } -internal class var -{ -}", -index: 1); + internal class var + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541641")] public async Task TestOnBadAttribute() { await TestInRegularAndScriptAsync( -@"[[|AttClass|]()] -class C -{ -} + """ + [[|AttClass|]()] + class C + { + } -internal class AttClassAttribute -{ -}", -@"using System; + internal class AttClassAttribute + { + } + """, + """ + using System; -[AttClass()] -class C -{ -} + [AttClass()] + class C + { + } -internal class AttClassAttribute : Attribute -{ -} + internal class AttClassAttribute : Attribute + { + } -internal class AttClassAttribute -{ -}", -index: 1); + internal class AttClassAttribute + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542528")] public async Task TestGenerateStruct1() { await TestInRegularAndScriptAsync( -@"using System; + """ + using System; -class A where T : struct -{ -} + class A where T : struct + { + } -class Program -{ - static void Main() - { - new A<[|S|]>(); - } -}", -@"using System; + class Program + { + static void Main() + { + new A<[|S|]>(); + } + } + """, + """ + using System; -class A where T : struct -{ -} + class A where T : struct + { + } -class Program -{ - static void Main() - { - new A(); - } -} + class Program + { + static void Main() + { + new A(); + } + } -internal struct S -{ -}", -index: 1); + internal struct S + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542480")] public async Task TestCopyConstraints1() { await TestInRegularAndScriptAsync( -@"class A where T : class -{ -} + """ + class A where T : class + { + } -class Program -{ - static void Goo() where T : class - { - A a = new [|B|](); - } -}", -@"class A where T : class -{ -} + class Program + { + static void Goo() where T : class + { + A a = new [|B|](); + } + } + """, + """ + class A where T : class + { + } -class Program -{ - static void Goo() where T : class - { - A a = new B(); - } -} + class Program + { + static void Goo() where T : class + { + A a = new B(); + } + } -internal class B : A where T : class -{ -}", -index: 1); + internal class B : A where T : class + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542528")] public async Task TestGenerateStruct2() { await TestInRegularAndScriptAsync( -@"using System; + """ + using System; -class A where T : struct -{ -} + class A where T : struct + { + } -class Program -{ - static void Main() - { - new A(); - } -}", -@"using System; + class Program + { + static void Main() + { + new A(); + } + } + """, + """ + using System; -class A where T : struct -{ -} + class A where T : struct + { + } -class Program -{ - static void Main() - { - new A(); - } + class Program + { + static void Main() + { + new A(); + } - private struct S - { - } -}"); + private struct S + { + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542528")] public async Task TestGenerateStruct3() { await TestInRegularAndScriptAsync( -@"using System; + """ + using System; -class Program -{ - static void Main() - { - Goo(); - } + class Program + { + static void Main() + { + Goo(); + } - static void Goo() where T : struct - { - } -}", -@"using System; + static void Goo() where T : struct + { + } + } + """, + """ + using System; -class Program -{ - static void Main() - { - Goo(); - } + class Program + { + static void Main() + { + Goo(); + } - static void Goo() where T : struct - { - } + static void Goo() where T : struct + { + } - private struct S - { - } -}"); + private struct S + { + } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542761")] public async Task TestGenerateOpenType1() { await TestInRegularAndScriptAsync( -@"class Program -{ - static void Main() - { - var x = typeof([|C<,>|]); - } -}", -@"class Program -{ - static void Main() - { - var x = typeof(C<,>); - } -} + """ + class Program + { + static void Main() + { + var x = typeof([|C<,>|]); + } + } + """, + """ + class Program + { + static void Main() + { + var x = typeof(C<,>); + } + } -internal class C -{ -}", -index: 1); + internal class C + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542766")] public async Task TestGenerateAttributeInGenericType() { await TestActionCountAsync( -@"using System; + """ + using System; -class A -{ - [[|C|]] - void Goo() - { - } -}", -count: 6); + class A + { + [[|C|]] + void Goo() + { + } + } + """, + count: 6); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543061")] public async Task TestNestedGenericAccessibility() { await TestInRegularAndScriptAsync( -@"using System.Collections.Generic; + """ + using System.Collections.Generic; -public class C -{ - public void Goo(List<[|NewClass|]> x) - { - } -}", -@"using System.Collections.Generic; + public class C + { + public void Goo(List<[|NewClass|]> x) + { + } + } + """, + """ + using System.Collections.Generic; -public class C -{ - public void Goo(List x) - { - } -} + public class C + { + public void Goo(List x) + { + } + } -public class NewClass -{ -}", -index: 1); + public class NewClass + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543493")] public async Task MissingIfNotInTypeStatementOrExpressionContext() { await TestMissingInRegularAndScriptAsync( -@"class C -{ - void M() - { - a [|b|] c d } -}"); + """ + class C + { + void M() + { + a [|b|] c d } + } + """); await TestMissingInRegularAndScriptAsync( -@"class C -{ - void M() - { - a b [|c|] d } -}"); + """ + class C + { + void M() + { + a b [|c|] d } + } + """); await TestMissingInRegularAndScriptAsync( -@"class C -{ - void M() - { - a b c [|d|] } -}"); + """ + class C + { + void M() + { + a b c [|d|] } + } + """); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542641")] public async Task TestAttributeSuffixOnAttributeSubclasses() { await TestInRegularAndScriptAsync( -@"using System.Runtime.CompilerServices; + """ + using System.Runtime.CompilerServices; -class Program -{ - static void Main(string[] args) - { - CustomConstantAttribute a = new [|GooAttribute|](); - } -}", -@"using System.Runtime.CompilerServices; + class Program + { + static void Main(string[] args) + { + CustomConstantAttribute a = new [|GooAttribute|](); + } + } + """, + """ + using System.Runtime.CompilerServices; -class Program -{ - static void Main(string[] args) - { - CustomConstantAttribute a = new GooAttribute(); - } -} + class Program + { + static void Main(string[] args) + { + CustomConstantAttribute a = new GooAttribute(); + } + } -internal class GooAttribute : CustomConstantAttribute -{ -}", -index: 1); + internal class GooAttribute : CustomConstantAttribute + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543853")] public async Task TestDisplayStringForGlobalNamespace() { await TestSmartTagTextAsync( -@"class C : [|Goo|]", -string.Format(FeaturesResources.Generate_0_1_in_new_file, "class", "Goo")); + @"class C : [|Goo|]", + string.Format(FeaturesResources.Generate_0_1_in_new_file, "class", "Goo")); } [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543853")] public async Task TestAddDocumentForGlobalNamespace() { await TestAddDocumentInRegularAndScriptAsync( -@"class C : [|Goo|]", -@"internal class Goo -{ -}", -ImmutableArray.Empty, -"Goo.cs"); + @"class C : [|Goo|]", + """ + internal class Goo + { + } + """, + ImmutableArray.Empty, + "Goo.cs"); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543886")] public async Task TestVerbatimAttribute() { await TestInRegularAndScriptAsync( -@"[[|@X|]] -class Class3 -{ -}", -@"using System; + """ + [[|@X|]] + class Class3 + { + } + """, + """ + using System; -[@X] -class Class3 -{ -} + [@X] + class Class3 + { + } -internal class X : Attribute -{ -}", -index: 1); + internal class X : Attribute + { + } + """, + index: 1); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531220")] public async Task CompareIncompleteMembersToEqual() { await TestInRegularAndScriptAsync( -@"class C -{ - X.X,X class X - { - X - } + """ + class C + { + X.X,X class X + { + X + } - X void X