提交 0bc9e748 编写于 作者: B Balaji Krishnan

update IntroduceVariable Tests to pass in..

.. new use var options
上级 b3b13793
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.CodeRefactorings.IntroduceVariable;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.Options;
......@@ -17,6 +18,21 @@ protected override object CreateCodeRefactoringProvider(Workspace workspace)
return new IntroduceVariableCodeRefactoringProvider();
}
private readonly SimpleCodeStyleOption onWithInfo = new SimpleCodeStyleOption(true, NotificationOption.Info);
// specify all options explicitly to override defaults.
private IDictionary<OptionKey, object> ImplicitTypingEverywhere() =>
OptionSet(CSharpCodeStyleOptions.UseImplicitTypeWherePossible, onWithInfo)
.With(CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, onWithInfo)
.With(CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, onWithInfo);
internal IDictionary<OptionKey, object> OptionSet(OptionKey option, object value)
{
var options = new Dictionary<OptionKey, object>();
options.Add(option, value);
return options;
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
public async Task TestMethodFix1()
{
......@@ -261,7 +277,8 @@ public async Task TestMethodFixComplexName1()
await TestAsync(
@"class C { static int Baz; void Foo() { Bar([|C.Baz|]); Bar(1 + 1); } }",
@"class C { static int Baz; void Foo() { var {|Rename:baz|} = C.Baz; Bar(baz); Bar(1 + 1); } }",
index: 0);
index: 0,
options: ImplicitTypingEverywhere());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
......@@ -289,7 +306,8 @@ public async Task TestNameConflict2()
await TestAsync(
@"using System ; class Program { private static int v = 5 ; static void Main ( string [ ] args ) { Func < int , int > d = ( x ) => { return [|x * v|] ; } ; d . Invoke ( v ) ; } } ",
@"using System ; class Program { private static int v = 5 ; static void Main ( string [ ] args ) { Func < int , int > d = ( x ) => { var {|Rename:v1|} = x * v; return v1 ; } ; d . Invoke ( v ) ; } } ",
index: 0);
index: 0,
options: ImplicitTypingEverywhere());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
......@@ -308,7 +326,8 @@ public async Task TestNameVerbatimIdentifier1()
await TestAsync(
@"static class G<T> { public class @class { } public static void Add(object t) { } } class Program { static void Main() { G<int>.Add([|new G<int>.@class()|]); } }",
@"static class G<T> { public class @class { } public static void Add(object t) { } } class Program { static void Main() { var {|Rename:@class|} = new G<int>.@class(); G<int>.Add(@class); } }",
index: 0);
index: 0,
options: ImplicitTypingEverywhere());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
......@@ -326,7 +345,8 @@ public async Task TestNameVerbatimIdentifier2()
{
await TestAsync(
@"static class G<T> { public class @class { } public static void Add(object t) { } static void Main() { G<int>.Add([|new G<int>.@class()|]); } }",
@"static class G<T> { public class @class { } public static void Add(object t) { } static void Main() { var {|Rename:class1|} = new G<int>.@class(); G<int>.Add(class1); } }");
@"static class G<T> { public class @class { } public static void Add(object t) { } static void Main() { var {|Rename:class1|} = new G<int>.@class(); G<int>.Add(class1); } }",
options: ImplicitTypingEverywhere());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
......@@ -377,7 +397,8 @@ public async Task TestCantExtractMethodTypeParameterToField()
{
await TestAsync(
@"using System ; using System . Collections . Generic ; using System . Linq ; class Program { static void Main < T > ( string [ ] args ) { Foo ( [|( T ) 2 . ToString ( )|] ) ; } } ",
@"using System ; using System . Collections . Generic ; using System . Linq ; class Program { static void Main < T > ( string [ ] args ) { var {|Rename:t|} = ( T ) 2 . ToString ( ) ; Foo ( t ) ; } } ");
@"using System ; using System . Collections . Generic ; using System . Linq ; class Program { static void Main < T > ( string [ ] args ) { var {|Rename:t|} = ( T ) 2 . ToString ( ) ; Foo ( t ) ; } } ",
options: ImplicitTypingEverywhere());
}
[WorkItem(540468, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540468")]
......@@ -554,7 +575,8 @@ public async Task TestImplicitlyTypedArraysUsedInCheckedExpression()
{
await TestAsync(
@"class Program { static void Main ( string [ ] args ) { int [ ] a = null ; int [ ] temp = checked ( [|a = new [ ] { 1 , 2 , 3 }|] ) ; } } ",
@"class Program { static void Main ( string [ ] args ) { int [ ] a = null ; var {|Rename:v|} = a = new [ ] { 1 , 2 , 3 } ; int [ ] temp = checked ( v ) ; } } ");
@"class Program { static void Main ( string [ ] args ) { int [ ] a = null ; var {|Rename:v|} = a = new [ ] { 1 , 2 , 3 } ; int [ ] temp = checked ( v ) ; } } ",
options: ImplicitTypingEverywhere());
}
[WorkItem(543832, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543832")]
......@@ -1084,7 +1106,7 @@ static void Main()
}
}",
compareTokens: false);
compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(606347, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/606347")]
......@@ -1186,7 +1208,8 @@ public async Task TestLambdaParameter1()
{
await TestAsync(
@"using System ; class Program { static void Main ( string [ ] args ) { Func < int , int > f = x => [|x + 1|] ; } } ",
@"using System ; class Program { static void Main ( string [ ] args ) { Func < int , int > f = x => { var {|Rename:v|} = x + 1 ; return v; }; } } ");
@"using System ; class Program { static void Main ( string [ ] args ) { Func < int , int > f = x => { var {|Rename:v|} = x + 1 ; return v; }; } } ",
options: ImplicitTypingEverywhere());
}
[WorkItem(530480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530480")]
......@@ -1195,7 +1218,8 @@ public async Task TestLambdaParameter2()
{
await TestAsync(
@"using System ; class Program { static void Main ( string [ ] args ) { Func < int , Func < int , int > > f = x => y => [|x + 1|] ; } } ",
@"using System ; class Program { static void Main ( string [ ] args ) { Func < int , Func < int , int > > f = x => { var {|Rename:v|} = x + 1 ; return y => v; }; } } ");
@"using System ; class Program { static void Main ( string [ ] args ) { Func < int , Func < int , int > > f = x => { var {|Rename:v|} = x + 1 ; return y => v; }; } } ",
options: ImplicitTypingEverywhere());
}
[WorkItem(530480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530480")]
......@@ -1204,7 +1228,8 @@ public async Task TestLambdaParameter3()
{
await TestAsync(
@"using System ; class Program { static void Main ( string [ ] args ) { Func < int , Func < int , int > > f = x => y => [|y + 1|] ; } } ",
@"using System ; class Program { static void Main ( string [ ] args ) { Func < int , Func < int , int > > f = x => y =>{ var {|Rename:v|} = y + 1 ; return v; }; } } ");
@"using System ; class Program { static void Main ( string [ ] args ) { Func < int , Func < int , int > > f = x => y =>{ var {|Rename:v|} = y + 1 ; return v; }; } } ",
options: ImplicitTypingEverywhere());
}
[WorkItem(530480, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530480")]
......@@ -1240,7 +1265,8 @@ public async Task TestNullableOfPointerType()
{
await TestAsync(
@"using System ; class Program { static void Main ( ) { [|new Nullable < int * > ( )|] . GetValueOrDefault ( ) ; } } ",
@"using System ; class Program { static void Main ( ) { var {|Rename:v|} = new Nullable < int * > ( ) ; v . GetValueOrDefault ( ) ; } } ");
@"using System ; class Program { static void Main ( ) { var {|Rename:v|} = new Nullable < int * > ( ) ; v . GetValueOrDefault ( ) ; } } ",
options: ImplicitTypingEverywhere());
}
[WorkItem(530919, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530919")]
......@@ -1259,7 +1285,8 @@ public async Task TestIntroduceLocalRemovesUnnecessaryCast()
{
await TestAsync(
@"using System.Collections.Generic; class C { static void Main(string[] args) { var set = new HashSet<string>(); set.Add([|set.ToString()|]); } } ",
@"using System.Collections.Generic; class C { static void Main(string[] args) { var set = new HashSet<string>(); var {|Rename:v|} = set.ToString(); set.Add(v); } } ");
@"using System.Collections.Generic; class C { static void Main(string[] args) { var set = new HashSet<string>(); var {|Rename:v|} = set.ToString(); set.Add(v); } } ",
options: ImplicitTypingEverywhere());
}
[WorkItem(655498, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/655498")]
......@@ -1357,7 +1384,7 @@ static void Main(string[] args)
d.Add(""a"", exception);
}
}",
compareTokens: false);
compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(884961, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/884961")]
......@@ -1384,7 +1411,7 @@ void M()
var l = new List<int>() { tickCount };
}
}",
compareTokens: false);
compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(884961, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/884961")]
......@@ -1443,7 +1470,7 @@ static int Main(string[] args)
return new Program { A = { { v, 0 } } }.A.Count;
}
}",
compareTokens: false);
compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(884961, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/884961")]
......@@ -1470,7 +1497,7 @@ void M()
var a = new int[] { tickCount };
}
}",
compareTokens: false);
compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(884961, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/884961")]
......@@ -1534,7 +1561,8 @@ void M()
}
}",
index: 1,
compareTokens: false);
compareTokens: false,
options: ImplicitTypingEverywhere());
}
[WorkItem(939259, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/939259")]
......@@ -1620,7 +1648,7 @@ void Foo()
}
}";
await TestAsync(code, expected, index: 0, compareTokens: false);
await TestAsync(code, expected, index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(1037057, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1037057")]
......@@ -1650,7 +1678,7 @@ void M()
int y = v * (x + 5);
}
}
", index: 0, compareTokens: false);
", index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(1065661, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1065661")]
......@@ -1697,7 +1725,7 @@ static void Foo(string s)
}
}";
await TestAsync(code, expected, index: 0, compareTokens: false);
await TestAsync(code, expected, index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(1097147, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1097147")]
......@@ -1725,7 +1753,7 @@ static void Foo(string s)
}
}";
await TestAsync(code, expected, index: 0, compareTokens: false);
await TestAsync(code, expected, index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(1097147, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1097147")]
......@@ -1771,7 +1799,7 @@ class B
public int Length { get; set; }
}";
await TestAsync(code, expected, index: 0, compareTokens: false);
await TestAsync(code, expected, index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(1097147, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1097147")]
......@@ -1819,7 +1847,7 @@ class B
public int GetAge() { return age; }
}";
await TestAsync(code, expected, index: 0, compareTokens: false);
await TestAsync(code, expected, index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(528, "http://github.com/dotnet/roslyn/issues/528")]
......@@ -1907,7 +1935,7 @@ private Complex Add(int b)
}
}";
await TestAsync(code, expected, index: 0, compareTokens: false);
await TestAsync(code, expected, index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(528, "http://github.com/dotnet/roslyn/issues/528")]
......@@ -2084,7 +2112,7 @@ class SampleCollection<T>
}
}";
await TestAsync(code, expected, index: 0, compareTokens: false);
await TestAsync(code, expected, index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(528, "http://github.com/dotnet/roslyn/issues/528")]
......@@ -2385,7 +2413,7 @@ static void Test(string[] args)
}
}";
await TestAsync(code, expected, index: 0, compareTokens: false);
await TestAsync(code, expected, index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(976, "https://github.com/dotnet/roslyn/issues/976")]
......@@ -2415,7 +2443,7 @@ static void Test(string[] args)
}
}";
await TestAsync(code, expected, index: 1, compareTokens: false);
await TestAsync(code, expected, index: 1, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(909152, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/909152")]
......@@ -2463,7 +2491,7 @@ public T F<T>(T x)
}
}";
await TestAsync(code, expected, index: 0, compareTokens: false);
await TestAsync(code, expected, index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(1130990, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1130990")]
......@@ -2493,7 +2521,7 @@ public T F<T>(T x)
}
}";
await TestAsync(code, expected, index: 0, compareTokens: false);
await TestAsync(code, expected, index: 0, compareTokens: false, options: ImplicitTypingEverywhere());
}
[WorkItem(1130990, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1130990")]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册