Skip to content

Commit

Permalink
Simplify test harness.
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Feb 28, 2017
1 parent 1ec0b0e commit b939629
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ internal Task TestAllOptionsOffAsync(
ParseOptions parseOptions = null,
CompilationOptions compilationOptions = null,
int index = 0, bool compareTokens = true,
IDictionary<OptionKey, object> options = null,
bool withScriptOption = false)
IDictionary<OptionKey, object> options = null)
{
options = options ?? new Dictionary<OptionKey, object>();
foreach (var kvp in AllOptionsOff)
Expand All @@ -41,8 +40,7 @@ internal Task TestAllOptionsOffAsync(
}

return TestAsync(initialMarkup, expectedMarkup,
parseOptions, compilationOptions, index, compareTokens, options,
withScriptOption: withScriptOption);
parseOptions, compilationOptions, index, compareTokens, options);
}

[Fact, Trait(Traits.Feature, Traits.Features.EncapsulateField)]
Expand Down Expand Up @@ -1397,7 +1395,8 @@ void M()
}
}
";
await TestAllOptionsOffAsync(text, expected, compareTokens: false, index: 1, parseOptions: TestOptions.Regular, withScriptOption: true);
await TestAllOptionsOffAsync(
text, expected, compareTokens: false, index: 1);
}

[Fact, Trait(Traits.Feature, Traits.Features.EncapsulateField), Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.Tuples)]
Expand Down Expand Up @@ -1439,7 +1438,8 @@ void M()
}
}
";
await TestAllOptionsOffAsync(text, expected, compareTokens: false, index: 1, parseOptions: TestOptions.Regular, withScriptOption: true);
await TestAllOptionsOffAsync(
text, expected, compareTokens: false, index: 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ static void Main(string[] args)
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors), Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.Tuples)]
public async Task Tuple()
{
await TestAsync(
await TestInRegularAndScriptAsync(
@"class C : [||]B
{
}
Expand All @@ -784,16 +784,13 @@ class B
public B((int, string) x)
{
}
}",
index: 0,
parseOptions: TestOptions.Regular,
withScriptOption: true);
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateDefaultConstructors), Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.Tuples)]
public async Task TupleWithNames()
{
await TestAsync(
await TestInRegularAndScriptAsync(
@"class C : [||]B
{
}
Expand All @@ -816,10 +813,7 @@ class B
public B((int a, string b) x)
{
}
}",
index: 0,
parseOptions: TestOptions.Regular,
withScriptOption: true);
}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3889,7 +3889,8 @@ public async Task ElementOfTuple()
var i = (1, V).ToString();
}";

await TestAsync(code, expected, index: 0, compareTokens: false, parseOptions: TestOptions.Regular, withScriptOption: true);
await TestInRegularAndScriptAsync(
code, expected, compareTokens: false);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
Expand All @@ -3908,7 +3909,7 @@ public async Task Tuple_IntroduceConstant()
var i = p.ToString();
}";

await TestAsync(code, expected, index: 0, compareTokens: false, parseOptions: TestOptions.Regular, withScriptOption: true);
await TestInRegularAndScriptAsync(code, expected, compareTokens: false);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
Expand All @@ -3927,7 +3928,7 @@ public async Task TupleWithNames_IntroduceConstant()
var i = p.ToString();
}";

await TestAsync(code, expected, index: 0, compareTokens: false, parseOptions: TestOptions.Regular, withScriptOption: true);
await TestInRegularAndScriptAsync(code, expected, compareTokens: false);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
Expand All @@ -3946,7 +3947,7 @@ public async Task Tuple_IntroduceConstantForAllOccurrences()
var i = p.ToString() + p.ToString();
}";

await TestAsync(code, expected, index: 1, compareTokens: false, parseOptions: TestOptions.Regular, withScriptOption: true);
await TestInRegularAndScriptAsync(code, expected, index: 1, compareTokens: false);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
Expand All @@ -3965,7 +3966,7 @@ public async Task TupleWithNames_IntroduceConstantForAllOccurrences()
var i = p.ToString() + p.ToString();
}";

await TestAsync(code, expected, index: 1, compareTokens: false, parseOptions: TestOptions.Regular, withScriptOption: true);
await TestInRegularAndScriptAsync(code, expected, index: 1, compareTokens: false);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
Expand All @@ -3984,7 +3985,7 @@ public async Task TupleWithDifferentNames_IntroduceConstantForAllOccurrences()
var i = p.ToString() + (c: 1, d: ""hello"").ToString();
}";

await TestAsync(code, expected, index: 1, compareTokens: false, parseOptions: TestOptions.Regular, withScriptOption: true);
await TestInRegularAndScriptAsync(code, expected, index: 1, compareTokens: false);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
Expand All @@ -4003,7 +4004,7 @@ public async Task TupleWithOneName_IntroduceConstantForAllOccurrences()
var i = p.ToString() + p.ToString();
}";

await TestAsync(code, expected, index: 1, compareTokens: false, parseOptions: TestOptions.Regular, withScriptOption: true);
await TestInRegularAndScriptAsync(code, expected, index: 1, compareTokens: false);

// no third action available
await TestActionCountAsync(code, 2, parseOptions: TestOptions.Regular);
Expand All @@ -4014,7 +4015,7 @@ public async Task Tuple_IntroduceLocalForAllOccurrences()
{
// Cannot refactor tuple as local constant
await Assert.ThrowsAsync<Xunit.Sdk.InRangeException>(() =>
TestAsync(
TestInRegularAndScriptAsync(
@"class C
{
void Foo()
Expand All @@ -4024,10 +4025,7 @@ void Foo()
}
}",
@"",
index: 3,
parseOptions: TestOptions.Regular,
withScriptOption: true)
);
index: 3));
}

[WorkItem(11777, "https://github.com/dotnet/roslyn/issues/11777")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ static void Main(string[] args)
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveDeclarationNearReference)]
public async Task Tuple()
{
await TestAsync(
await TestInRegularAndScriptAsync(
@"class C
{
void M()
Expand All @@ -610,16 +610,13 @@ void M()
Console.WriteLine(x);
}
}
}",
index: 0,
parseOptions: TestOptions.Regular,
withScriptOption: true);
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveDeclarationNearReference)]
public async Task TupleWithNames()
{
await TestAsync(
await TestInRegularAndScriptAsync(
@"class C
{
void M()
Expand All @@ -639,10 +636,7 @@ void M()
Console.WriteLine(x);
}
}
}",
index: 0,
parseOptions: TestOptions.Regular,
withScriptOption: true);
}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,7 @@ await TestWithAllCodeStyleOff(
{
}
}
}",
parseOptions: TestOptions.Regular,
withScriptOption: true);
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)]
Expand Down Expand Up @@ -1251,9 +1249,7 @@ class C
}
}
}" + TestResources.NetFX.ValueTuple.tuplelib_cs,
index: 1,
parseOptions: TestOptions.Regular,
withScriptOption: true);
index: 1);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)]
Expand Down Expand Up @@ -1287,9 +1283,7 @@ class C
}
}
}" + TestResources.NetFX.ValueTuple.tuplelib_cs,
index: 1,
parseOptions: TestOptions.Regular,
withScriptOption: true);
index: 1);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)]
Expand All @@ -1311,9 +1305,7 @@ void setFoo((int c, string d) i)
}
}",
@"",
index: 1,
parseOptions: TestOptions.Regular,
withScriptOption: true));
index: 1));
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)]
Expand Down Expand Up @@ -1691,14 +1683,13 @@ await TestInRegularAndScriptAsync(
private async Task TestWithAllCodeStyleOff(
string initialMarkup, string expectedMarkup,
ParseOptions parseOptions = null, int index = 0,
bool compareTokens = true, bool withScriptOption = false)
bool compareTokens = true)
{
await TestAsync(
initialMarkup, expectedMarkup, parseOptions,
index: index,
compareTokens: compareTokens,
options: AllCodeStyleOff,
withScriptOption: withScriptOption);
options: AllCodeStyleOff);
}

private IDictionary<OptionKey, object> AllCodeStyleOff =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1106,8 +1106,7 @@ static class E
public static void Deconstruct(this Program p, out int x, out int y) { }
}
}",
parseOptions: null,
withScriptOption: false);
parseOptions: null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ class CAttribute
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsFullyQualify)]
public async Task TupleTest()
{
await TestAsync(
await TestInRegularAndScriptAsync(
@"class Class
{
([|IDictionary|], string) Method()
Expand All @@ -1253,15 +1253,13 @@ await TestAsync(
{
Foo();
}
}",
parseOptions: TestOptions.Regular,
withScriptOption: true);
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsFullyQualify)]
public async Task TupleWithOneName()
{
await TestAsync(
await TestInRegularAndScriptAsync(
@"class Class
{
([|IDictionary|] a, string) Method()
Expand All @@ -1275,9 +1273,7 @@ await TestAsync(
{
Foo();
}
}",
parseOptions: TestOptions.Regular,
withScriptOption: true);
}");
}
}
}
Loading

0 comments on commit b939629

Please sign in to comment.