提交 66be80fe 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #14840 from CyrusNajmabadi/multilineTests

Update tests to use multiline literals.
using System;
using System;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Diagnostics.AddBraces;
......@@ -21,115 +21,124 @@ public partial class AddBracesTests : AbstractCSharpDiagnosticProviderBasedUserD
public async Task DoNotFireForIfWithBraces()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
[|if|] (true) { return; }
[|if|] (true)
{
return;
}
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
public async Task DoNotFireForElseWithBraces()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
if (true) { return; }
[|else|] { return; }
if (true)
{
return;
}
[|else|]
{
return;
}
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
public async Task DoNotFireForElseWithChildIf()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
if (true) return;
[|else|] if (false) return;
if (true)
return;
[|else|] if (false)
return;
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
public async Task DoNotFireForForWithBraces()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
[|for|] (var i = 0; i < 5; i++) { return; }
[|for|] (var i = 0; i < 5; i++)
{
return;
}
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
public async Task DoNotFireForForEachWithBraces()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
[|foreach|] (var c in ""test"") { return; }
[|foreach|] (var c in ""test"")
{
return;
}
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
public async Task DoNotFireForWhileWithBraces()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
[|while|] (true) { return; }
[|while|] (true)
{
return;
}
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
public async Task DoNotFireForDoWhileWithBraces()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
[|do|] { return; } while (true);
[|do|]
{
return;
}
while (true);
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
public async Task DoNotFireForUsingWithBraces()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
......@@ -146,16 +155,14 @@ public void Dispose()
{
throw new NotImplementedException();
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
public async Task DoNotFireForUsingWithChildUsing()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
......@@ -179,16 +186,14 @@ public void Dispose()
{
throw new NotImplementedException();
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
public async Task DoNotFireForLockWithBraces()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
......@@ -198,28 +203,24 @@ static void Main()
return;
}
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
public async Task DoNotFireForLockWithChildLock()
{
await TestMissingAsync(
@"
class Program
@"class Program
{
static void Main()
{
var str1 = ""test"";
var str2 = ""test"";
[|lock|] (str1)
lock (str2)
return;
lock (str2)
return;
}
}
");
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddBraces)]
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
......@@ -59,7 +59,8 @@ public partial class TotalClassifierTests : AbstractCSharpClassifierTests
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task VarAsUsingAliasForNamespace()
{
await TestAsync(@"using var = System;",
await TestAsync(
@"using var = System;",
Keyword("using"),
Identifier("var"),
Operators.Equals,
......@@ -70,7 +71,10 @@ public async Task VarAsUsingAliasForNamespace()
[Fact, Trait(Traits.Feature, Traits.Features.Classification), WorkItem(547068, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/547068")]
public async Task Bug17819()
{
await TestAsync(@"_ _(){}
await TestAsync(
@"_ _()
{
}
///<param name='_
}",
Identifier("_"),
......@@ -93,7 +97,8 @@ public async Task Bug17819()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task VarAsUsingAliasForClass()
{
await TestAsync(@"using var = System.Math;",
await TestAsync(
@"using var = System.Math;",
Keyword("using"),
Class("var"),
Operators.Equals,
......@@ -106,7 +111,8 @@ public async Task VarAsUsingAliasForClass()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task VarAsUsingAliasForDelegate()
{
await TestAsync(@"using var = System.Action;",
await TestAsync(
@"using var = System.Action;",
Keyword("using"),
Delegate("var"),
Operators.Equals,
......@@ -119,7 +125,8 @@ public async Task VarAsUsingAliasForDelegate()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task VarAsUsingAliasForStruct()
{
await TestAsync(@"using var = System.DateTime;",
await TestAsync(
@"using var = System.DateTime;",
Keyword("using"),
Struct("var"),
Operators.Equals,
......@@ -132,7 +139,8 @@ public async Task VarAsUsingAliasForStruct()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task VarAsUsingAliasForEnum()
{
await TestAsync(@"using var = System.DayOfWeek;",
await TestAsync(
@"using var = System.DayOfWeek;",
Keyword("using"),
Enum("var"),
Operators.Equals,
......@@ -145,7 +153,8 @@ public async Task VarAsUsingAliasForEnum()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task VarAsUsingAliasForInterface()
{
await TestAsync(@"using var = System.IDisposable;",
await TestAsync(
@"using var = System.IDisposable;",
Keyword("using"),
Interface("var"),
Operators.Equals,
......@@ -158,7 +167,13 @@ public async Task VarAsUsingAliasForInterface()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task VarAsConstructorName()
{
await TestAsync(@"class var { var() { } }",
await TestAsync(
@"class var
{
var()
{
}
}",
Keyword("class"),
Class("var"),
Punctuation.OpenCurly,
......@@ -173,7 +188,8 @@ public async Task VarAsConstructorName()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task UsingAliasGlobalNamespace()
{
await TestAsync(@"using IO = global::System.IO;",
await TestAsync(
@"using IO = global::System.IO;",
Keyword("using"),
Identifier("IO"),
Operators.Equals,
......@@ -251,7 +267,17 @@ public async Task VarInForeach()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task ValueInSetterAndAnonymousTypePropertyName()
{
await TestAsync(@"class C { int P { set { var t = new { value = value }; } } }",
await TestAsync(
@"class C
{
int P
{
set
{
var t = new { value = value };
}
}
}",
Keyword("class"),
Class("C"),
Punctuation.OpenCurly,
......@@ -390,14 +416,14 @@ public async Task NewOfInterface()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task TestVarConstructor()
{
await TestAsync(@"class var
await TestAsync(
@"class var
{
void Main()
{
new var();
}
}
",
}",
Keyword("class"),
Class("var"),
Punctuation.OpenCurly,
......@@ -419,14 +445,14 @@ void Main()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task TestVarTypeParameter()
{
await TestAsync(@"class X
await TestAsync(
@"class X
{
void Foo<var>()
{
var x;
}
}
",
}",
Keyword("class"),
Class("X"),
Punctuation.OpenCurly,
......@@ -449,11 +475,13 @@ void Foo<var>()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task TestVarAttribute1()
{
await TestAsync(@"using System;
await TestAsync(
@"using System;
[var]
class var : Attribute { }
",
class var : Attribute
{
}",
Keyword("using"),
Identifier("System"),
Punctuation.Semicolon,
......@@ -472,11 +500,13 @@ class var : Attribute { }
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task TestVarAttribute2()
{
await TestAsync(@"using System;
await TestAsync(
@"using System;
[var]
class varAttribute : Attribute { }
",
class varAttribute : Attribute
{
}",
Keyword("using"),
Identifier("System"),
Punctuation.Semicolon,
......@@ -495,7 +525,9 @@ class varAttribute : Attribute { }
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task TestStandaloneTypeName()
{
await TestAsync(@"using System;
await TestAsync(
@"using System;
class C
{
static void Main()
......@@ -527,14 +559,14 @@ static void Main()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task TestNamespaceClassAmbiguities()
{
await TestAsync(@"class C
await TestAsync(
@"class C
{
}
namespace C
{
}
",
}",
Keyword("class"),
Class("C"),
Punctuation.OpenCurly,
......@@ -548,11 +580,13 @@ namespace C
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task NameAttributeValue()
{
await TestAsync(@"
class Program<T>
await TestAsync(
@"class Program<T>
{
/// <param name=""x""/>
void Foo(int x) { }
void Foo(int x)
{
}
}",
Keyword("class"),
Class("Program"),
......@@ -585,10 +619,13 @@ class Program<T>
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task Cref1()
{
await TestAsync(@"/// <see cref=""Program{T}""/>
await TestAsync(
@"/// <see cref=""Program{T}""/>
class Program<T>
{
void Foo() { }
void Foo()
{
}
}",
XmlDoc.Delimiter("///"),
XmlDoc.Text(" "),
......@@ -622,7 +659,8 @@ class Program<T>
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task CrefNamespaceIsNotClass()
{
await TestAsync(@"/// <see cref=""N""/>
await TestAsync(
@"/// <see cref=""N""/>
namespace N
{
class Program
......@@ -653,9 +691,11 @@ class Program
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task InterfacePropertyWithSameNameShouldBePreferredToType()
{
await TestAsync(@"interface IFoo
await TestAsync(
@"interface IFoo
{
int IFoo { get; set; }
void Bar(int x = IFoo);
}",
Keyword("interface"),
......@@ -685,15 +725,16 @@ public async Task InterfacePropertyWithSameNameShouldBePreferredToType()
[WpfFact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task XmlDocCref()
{
await TestAsync(@"
/// <summary>
await TestAsync(
@"/// <summary>
/// <see cref=""MyClass.MyClass(int)""/>
/// </summary>
class MyClass
{
public MyClass(int x) { }
}
",
public MyClass(int x)
{
}
}",
XmlDoc.Delimiter("///"),
XmlDoc.Text(" "),
XmlDoc.Delimiter("<"),
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Roslyn.Test.Utilities;
......@@ -64,7 +64,8 @@ public async Task DynamicNullable()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsUsingAliasForClass()
{
await TestAsync(@"using dynamic = System.EventArgs;",
await TestAsync(
@"using dynamic = System.EventArgs;",
Keyword("using"),
Class("dynamic"),
Operators.Equals,
......@@ -77,7 +78,8 @@ public async Task DynamicAsUsingAliasForClass()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsUsingAliasForDelegate()
{
await TestAsync(@"using dynamic = System.Action;",
await TestAsync(
@"using dynamic = System.Action;",
Keyword("using"),
Delegate("dynamic"),
Operators.Equals,
......@@ -90,7 +92,8 @@ public async Task DynamicAsUsingAliasForDelegate()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsUsingAliasForStruct()
{
await TestAsync(@"using dynamic = System.DateTime;",
await TestAsync(
@"using dynamic = System.DateTime;",
Keyword("using"),
Struct("dynamic"),
Operators.Equals,
......@@ -103,7 +106,8 @@ public async Task DynamicAsUsingAliasForStruct()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsUsingAliasForEnum()
{
await TestAsync(@"using dynamic = System.DayOfWeek;",
await TestAsync(
@"using dynamic = System.DayOfWeek;",
Keyword("using"),
Enum("dynamic"),
Operators.Equals,
......@@ -116,7 +120,8 @@ public async Task DynamicAsUsingAliasForEnum()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsUsingAliasForInterface()
{
await TestAsync(@"using dynamic = System.IDisposable;",
await TestAsync(
@"using dynamic = System.IDisposable;",
Keyword("using"),
Interface("dynamic"),
Operators.Equals,
......@@ -129,8 +134,13 @@ public async Task DynamicAsUsingAliasForInterface()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsExternAlias()
{
await TestAsync(@"extern alias dynamic;
class C { dynamic::Foo a; }",
await TestAsync(
@"extern alias dynamic;
class C
{
dynamic::Foo a;
}",
Keyword("extern"),
Keyword("alias"),
Identifier("dynamic"),
......@@ -201,7 +211,15 @@ public async Task DynamicAsDelegateLocalVariable()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsGenericTypeName()
{
await TestAsync(@"partial class dynamic<T> { } class C { dynamic<int> d; }",
await TestAsync(
@"partial class dynamic<T>
{
}
class C
{
dynamic<int> d;
}",
Keyword("partial"),
Keyword("class"),
Class("dynamic"),
......@@ -225,7 +243,11 @@ public async Task DynamicAsGenericTypeName()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsGenericField()
{
await TestAsync(@"class A<T> { T dynamic; }",
await TestAsync(
@"class A<T>
{
T dynamic;
}",
Keyword("class"),
Class("A"),
Punctuation.OpenAngle,
......@@ -495,7 +517,10 @@ public async Task DynamicInExtensionMethod()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsBaseClass()
{
await TestAsync(@"class C : dynamic { }",
await TestAsync(
@"class C : dynamic
{
}",
Keyword("class"),
Class("C"),
Punctuation.Colon,
......@@ -507,7 +532,10 @@ public async Task DynamicAsBaseClass()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsGenericConstraint()
{
await TestAsync(@"class C<T> where T : dynamic { }",
await TestAsync(
@"class C<T> where T : dynamic
{
}",
Keyword("class"),
Class("C"),
Punctuation.OpenAngle,
......@@ -553,7 +581,10 @@ public async Task DynamicTypeOf()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsArrayName()
{
await TestAsync(@"int[] dynamic = { 1 };",
await TestAsync(
@"int[] dynamic = {
1
};",
Keyword("int"),
Punctuation.OpenBracket,
Punctuation.CloseBracket,
......@@ -599,7 +630,10 @@ public async Task DynamicAsLocalVariableName()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsNamespaceName()
{
await TestAsync(@"namespace dynamic { }",
await TestAsync(
@"namespace dynamic
{
}",
Keyword("namespace"),
Identifier("dynamic"),
Punctuation.OpenCurly,
......@@ -609,7 +643,10 @@ public async Task DynamicAsNamespaceName()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsClassName()
{
await TestAsync(@"class dynamic { }",
await TestAsync(
@"class dynamic
{
}",
Keyword("class"),
Class("dynamic"),
Punctuation.OpenCurly,
......@@ -619,7 +656,13 @@ public async Task DynamicAsClassName()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsConstructorDeclarationName()
{
await TestAsync(@"class dynamic { dynamic() { } }",
await TestAsync(
@"class dynamic
{
dynamic()
{
}
}",
Keyword("class"),
Class("dynamic"),
Punctuation.OpenCurly,
......@@ -675,7 +718,11 @@ public async Task DynamicAsEnumField()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsEnumFieldDefinition()
{
await TestAsync(@"enum A { dynamic }",
await TestAsync(
@"enum A
{
dynamic
}",
Keyword("enum"),
Enum("A"),
Punctuation.OpenCurly,
......@@ -686,7 +733,10 @@ public async Task DynamicAsEnumFieldDefinition()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsEnumType()
{
await TestAsync(@"enum dynamic { }",
await TestAsync(
@"enum dynamic
{
}",
Keyword("enum"),
Enum("dynamic"),
Punctuation.OpenCurly,
......@@ -696,7 +746,11 @@ public async Task DynamicAsEnumType()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsGenericTypeParameter()
{
await TestAsync(@"class C<dynamic, T> where dynamic : T { dynamic d; }",
await TestAsync(
@"class C<dynamic, T> where dynamic : T
{
dynamic d;
}",
Keyword("class"),
Class("C"),
Punctuation.OpenAngle,
......@@ -876,7 +930,10 @@ public async Task DynamicAsRegionLabel()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsInterfaceType()
{
await TestAsync(@"interface dynamic{}",
await TestAsync(
@"interface dynamic
{
}",
Keyword("interface"),
Interface("dynamic"),
Punctuation.OpenCurly,
......@@ -886,7 +943,10 @@ public async Task DynamicAsInterfaceType()
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task DynamicAsStructType()
{
await TestAsync(@"struct dynamic { }",
await TestAsync(
@"struct dynamic
{
}",
Keyword("struct"),
Struct("dynamic"),
Punctuation.OpenCurly,
......
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CSharp.CodeRefactorings.ConvertToInterpolatedString;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
......@@ -17,14 +17,16 @@ public async Task TestSingleItemSubstitution()
{
await TestAsync(
@"using System;
class T
{
void M()
{
var a = [|string.Format(""{0}"", 1)|];
}
}",
}",
@"using System;
class T
{
void M()
......@@ -39,6 +41,7 @@ public async Task TestItemOrdering()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -47,6 +50,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -61,6 +65,7 @@ public async Task TestItemOrdering2()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -69,6 +74,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -83,6 +89,7 @@ public async Task TestItemOrdering3()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -91,6 +98,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -105,6 +113,7 @@ public async Task TestItemOutsideRange()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -113,6 +122,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -127,6 +137,7 @@ public async Task TestItemDoNotHaveCast()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -135,6 +146,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -149,6 +161,7 @@ public async Task TestItemWithSyntaxErrorDoesHaveCast()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -157,6 +170,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -171,6 +185,7 @@ public async Task TestItemWithoutSyntaxErrorDoesNotHaveCast()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -179,6 +194,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -193,6 +209,7 @@ public async Task TestParenthesisAddedForTernaryExpression()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -201,6 +218,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -215,6 +233,7 @@ public async Task TestDoesNotAddDoubleParenthesisForTernaryExpression()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -223,6 +242,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -237,18 +257,18 @@ public async Task TestMultiLineExpression()
{
await TestAsync(
@"using System;
class T
{
void M()
{
var a = [|string.Format(
""{0}"",
true
? ""Yes""
: false as object)|];
""{0}"",
true ? ""Yes"" : false as object)|];
}
}",
@"using System;
class T
{
void M()
......@@ -263,6 +283,7 @@ public async Task TestFormatSpecifiers()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -273,6 +294,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -288,6 +310,7 @@ public async Task TestFormatSpecifiers2()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -296,6 +319,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -341,6 +365,7 @@ public async Task TestFormatSpecifiers4()
{
await TestAsync(
@"using System;
class T
{
void M()
......@@ -349,6 +374,7 @@ void M()
}
}",
@"using System;
class T
{
void M()
......@@ -363,19 +389,21 @@ public async Task TestFormatSpecifiers5()
{
await TestAsync(
@"using System;
public class T
{
public static void M()
{
Tuple<string, DateTime, int, DateTime, int>[] cities =
{ Tuple.Create(""Los Angeles"", new DateTime(1940, 1, 1), 1504277,
Tuple<string, DateTime, int, DateTime, int>[] cities = {
Tuple.Create(""Los Angeles"", new DateTime(1940, 1, 1), 1504277,
new DateTime(1950, 1, 1), 1970358),
Tuple.Create(""New York"", new DateTime(1940, 1, 1), 7454995,
new DateTime(1950, 1, 1), 7891957),
Tuple.Create(""Chicago"", new DateTime(1940, 1, 1), 3396808,
new DateTime(1950, 1, 1), 3620962),
Tuple.Create(""Detroit"", new DateTime(1940, 1, 1), 1623452,
new DateTime(1950, 1, 1), 1849568) };
new DateTime(1950, 1, 1), 1849568)
};
string output;
foreach (var city in cities)
{
......@@ -386,19 +414,21 @@ public static void M()
}
}",
@"using System;
public class T
{
public static void M()
{
Tuple<string, DateTime, int, DateTime, int>[] cities =
{ Tuple.Create(""Los Angeles"", new DateTime(1940, 1, 1), 1504277,
Tuple<string, DateTime, int, DateTime, int>[] cities = {
Tuple.Create(""Los Angeles"", new DateTime(1940, 1, 1), 1504277,
new DateTime(1950, 1, 1), 1970358),
Tuple.Create(""New York"", new DateTime(1940, 1, 1), 7454995,
new DateTime(1950, 1, 1), 7891957),
Tuple.Create(""Chicago"", new DateTime(1940, 1, 1), 3396808,
new DateTime(1950, 1, 1), 3620962),
Tuple.Create(""Detroit"", new DateTime(1940, 1, 1), 1623452,
new DateTime(1950, 1, 1), 1849568) };
new DateTime(1950, 1, 1), 1849568)
};
string output;
foreach (var city in cities)
{
......@@ -413,11 +443,18 @@ public async Task TestFormatSpecifiers6()
{
await TestAsync(
@"using System;
public class T
{
public static void M()
{
short[] values = { Int16.MinValue, -27, 0, 1042, Int16.MaxValue };
short[] values = {
Int16.MinValue,
-27,
0,
1042,
Int16.MaxValue
};
foreach (short value in values)
{
string formatString = [|String.Format(""{0,10:G}: {0,10:X}"", value)|];
......@@ -425,11 +462,18 @@ public static void M()
}
}",
@"using System;
public class T
{
public static void M()
{
short[] values = { Int16.MinValue, -27, 0, 1042, Int16.MaxValue };
short[] values = {
Int16.MinValue,
-27,
0,
1042,
Int16.MaxValue
};
foreach (short value in values)
{
string formatString = $""{value,10:G}: {value,10:X}"";
......@@ -488,11 +532,10 @@ public static void M()
decimal hiTemp = 62.1m;
TimeSpan loTime = new TimeSpan(3, 16, 10);
decimal loTemp = 54.8m;
string result = [|String.Format(@""Temperature on {0:d}:
string result = [|String.Format(@""Temperature on {0:d}:
{1,11}: {2} degrees (hi)
{3,11}: {4} degrees (lo)"",
new object[] { date1, hiTime, hiTemp, loTime, loTemp })|];
new object[] { date1, hiTime, hiTemp, loTime, loTemp })|];
}
}");
}
......@@ -526,6 +569,7 @@ public async Task TestOutVariableDeclaration_01()
{
await TestMissingAsync(
@"using System;
class T
{
void M()
......@@ -540,6 +584,7 @@ public async Task TestOutVariableDeclaration_02()
{
await TestMissingAsync(
@"using System;
class T
{
void M()
......
......@@ -1104,17 +1104,17 @@ public int MyInt
[Fact, Trait(Traits.Feature, Traits.Features.EncapsulateField)]
public async Task DoNotEncapsulateOutsideTypeDeclaration()
{
await TestMissingAsync(@"
var [|x|] = 1;");
await TestMissingAsync(
@"var [|x|] = 1;");
await TestMissingAsync(@"
namespace N
await TestMissingAsync(
@"namespace N
{
var [|x|] = 1;
}");
await TestMissingAsync(@"
enum E
await TestMissingAsync(
@"enum E
{
[|x|] = 1;
}");
......
......@@ -274,20 +274,39 @@ public async Task TestKeepTriviaWithinExpression()
public async Task TestMissingOnNonEmptySpan()
{
await TestMissingAsync(
@"class C { void F() { [|if (a) { a(); } else { b(); }|] } }");
@"class C
{
void F()
{
[|if (a)
{
a();
}
else
{
b();
}|]
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInvertIf)]
public async Task TestOverlapsHiddenPosition1()
{
await TestMissingAsync(
@"
class C
@"class C
{
void F()
{
#line hidden
[||]if (a) { a(); } else { b(); }
[||]if (a)
{
a();
}
else
{
b();
}
#line default
}
}");
......@@ -297,8 +316,7 @@ void F()
public async Task TestOverlapsHiddenPosition2()
{
await TestMissingAsync(
@"
class C
@"class C
{
void F()
{
......@@ -309,7 +327,7 @@ void F()
#line default
}
else
{
{
b();
}
}
......@@ -320,8 +338,7 @@ void F()
public async Task TestOverlapsHiddenPosition3()
{
await TestMissingAsync(
@"
class C
@"class C
{
void F()
{
......@@ -330,7 +347,7 @@ void F()
a();
}
else
{
{
#line hidden
b();
#line default
......@@ -343,8 +360,7 @@ void F()
public async Task TestOverlapsHiddenPosition4()
{
await TestMissingAsync(
@"
class C
@"class C
{
void F()
{
......@@ -354,7 +370,7 @@ void F()
a();
}
else
{
{
b();
#line default
}
......@@ -366,8 +382,7 @@ void F()
public async Task TestOverlapsHiddenPosition5()
{
await TestMissingAsync(
@"
class C
@"class C
{
void F()
{
......@@ -377,7 +392,7 @@ void F()
#line hidden
}
else
{
{
#line default
b();
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......@@ -69,13 +69,11 @@ public async Task TestSearchPackageSingleName()
.Returns(CreateSearchResult("NuGetPackage", "NuGetType", CreateNameParts("NuGetNamespace")));
await TestAsync(
@"
class C
@"class C
{
[|NuGetType|] n;
}",
@"
using NuGetNamespace;
@"using NuGetNamespace;
class C
{
......@@ -100,13 +98,11 @@ public async Task TestSearchPackageMultipleNames()
.Returns(CreateSearchResult("NuGetPackage", "NuGetType", CreateNameParts("NS1", "NS2")));
await TestAsync(
@"
class C
@"class C
{
[|NuGetType|] n;
}",
@"
using NS1.NS2;
@"using NS1.NS2;
class C
{
......@@ -131,8 +127,7 @@ public async Task TestMissingIfPackageAlreadyInstalled()
.Returns(CreateSearchResult("NuGetPackage", "NuGetType", CreateNameParts("NS1", "NS2")));
await TestMissingAsync(
@"
class C
@"class C
{
[|NuGetType|] n;
}", fixProviderData: new FixProviderData(installerServiceMock.Object, packageServiceMock.Object));
......@@ -201,13 +196,11 @@ public async Task TestInstallGetsCalledNoVersion()
.Returns(CreateSearchResult("NuGetPackage", "NuGetType", CreateNameParts("NuGetNamespace")));
await TestAsync(
@"
class C
@"class C
{
[|NuGetType|] n;
}",
@"
using NuGetNamespace;
@"using NuGetNamespace;
class C
{
......@@ -232,13 +225,11 @@ public async Task TestInstallGetsCalledWithVersion()
.Returns(CreateSearchResult("NuGetPackage", "NuGetType", CreateNameParts("NuGetNamespace")));
await TestAsync(
@"
class C
@"class C
{
[|NuGetType|] n;
}",
@"
using NuGetNamespace;
@"using NuGetNamespace;
class C
{
......@@ -264,13 +255,11 @@ public async Task TestFailedInstallRollsBackFile()
.Returns(CreateSearchResult("NuGetPackage", "NuGetType", CreateNameParts("NuGetNamespace")));
await TestAsync(
@"
class C
@"class C
{
[|NuGetType|] n;
}",
@"
class C
@"class C
{
NuGetType n;
}", systemSpecialCase: false, fixProviderData: new FixProviderData(installerServiceMock.Object, packageServiceMock.Object));
......
......@@ -12,16 +12,63 @@ public partial class AddUsingTests : AbstractCSharpDiagnosticProviderBasedUserDi
public async Task TestSimpleQuery()
{
await TestAsync(
@"using System ; using System . Collections . Generic ; class Program { static void Main ( string [ ] args ) { var q = [|from x in args select x|]} } ",
@"using System ; using System . Collections . Generic ; using System . Linq ; class Program { static void Main ( string [ ] args ) { var q = from x in args select x} } ");
@"using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
var q = [|from x in args
select x|]}
}",
@"using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var q = from x in args
select x}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddUsing)]
public async Task TestSimpleWhere()
{
await TestAsync(
@"class Test { public void SimpleWhere ( ) { int [ ] numbers = { 1 , 2 , 3 } ; var lowNums = [|from n in numbers where n < 5 select n|] ; } } ",
@"using System . Linq ; class Test { public void SimpleWhere ( ) { int [ ] numbers = { 1 , 2 , 3 } ; var lowNums = from n in numbers where n < 5 select n ; } } ");
@"class Test
{
public void SimpleWhere()
{
int[] numbers = {
1,
2,
3
};
var lowNums = [|from n in numbers
where n < 5
select n|];
}
}",
@"using System.Linq;
class Test
{
public void SimpleWhere()
{
int[] numbers = {
1,
2,
3
};
var lowNums = from n in numbers
where n < 5
select n;
}
}");
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.CSharp.KeywordHighlighting.KeywordHighlighters;
......@@ -20,6 +20,7 @@ public async Task TestExample3_1()
await TestAsync(
@"using System;
using System.Threading.Tasks;
class AsyncExample
{
async Task<int> AsyncMethod()
......@@ -30,20 +31,15 @@ async Task<int> AsyncMethod()
async Task UseAsync()
{
Func<Task<int>> lambda = {|Cursor:[|async|]|} delegate
{
Func<Task<int>> lambda = {|Cursor:[|async|]|} delegate {
return [|await|] AsyncMethod();
};
int result = await AsyncMethod();
Task<int> resultTask = AsyncMethod();
result = await resultTask;
result = await lambda();
}
}
");
}");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册