Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify classification on var pattern #61376

Merged
merged 2 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2752,45 +2752,6 @@ static void Main(string[] args)
Property("Length"));
}

[WpfTheory(Skip = "https://github.com/dotnet/roslyn/issues/30855")]
[CombinatorialData]
[WorkItem(18956, "https://github.com/dotnet/roslyn/issues/18956")]
public async Task TestVarInPattern1(TestHost testHost)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The classification is no longer semantic for this kind of var. It is syntactic. So the coverage comes from syntactic classifier tests now.

Copy link
Member

@Youssef1313 Youssef1313 May 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally keep the test and document the current behavior. But @CyrusNajmabadi for suggestion/his preference.

{
await TestAsync(
@"
class Program
{
void Main(string s)
{
if (s is var v)
{
}
}
}", testHost,
Parameter("s"), Keyword("var"));
}

[WpfTheory(Skip = "https://github.com/dotnet/roslyn/issues/30855")]
[CombinatorialData]
[WorkItem(18956, "https://github.com/dotnet/roslyn/issues/18956")]
public async Task TestVarInPattern2(TestHost testHost)
{
await TestAsync(
@"
class Program
{
void Main(string s)
{
switch (s)
{
case var v:
}
}
}", testHost,
Parameter("s"), Keyword("var"));
}

[Theory]
[CombinatorialData]
[WorkItem(23940, "https://github.com/dotnet/roslyn/issues/23940")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5033,27 +5033,28 @@ await TestInMethodAsync(@"

[Theory]
[CombinatorialData]
[WorkItem(18956, "https://github.com/dotnet/roslyn/issues/18956")]
public async Task TestListPattern(TestHost testHost)
{
await TestInMethodAsync(@"
_ = new int[0] switch
switch (new int[0])
{
case [1, 2]:
break;
case [1, .. var end]:
break;
}",
testHost,
Identifier("_"),
Operators.Equals,
testHost,
ControlKeyword("switch"),
Punctuation.OpenParen,
Keyword("new"),
Keyword("int"),
Punctuation.OpenBracket,
Number("0"),
Punctuation.CloseBracket,
ControlKeyword("switch"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("case"),
ControlKeyword("case"),
Punctuation.OpenBracket,
Number("1"),
Punctuation.Comma,
Expand All @@ -5062,12 +5063,12 @@ await TestInMethodAsync(@"
Punctuation.Colon,
ControlKeyword("break"),
Punctuation.Semicolon,
Keyword("case"),
ControlKeyword("case"),
Punctuation.OpenBracket,
Number("1"),
Punctuation.Comma,
Punctuation.DotDot,
Identifier("var"),
Keyword("var"),
Identifier("end"),
Punctuation.CloseBracket,
Punctuation.Colon,
Expand All @@ -5076,6 +5077,53 @@ await TestInMethodAsync(@"
Punctuation.CloseCurly);
}

[Theory]
[CombinatorialData]
[WorkItem(18956, "https://github.com/dotnet/roslyn/issues/18956")]
public async Task TestListPattern2(TestHost testHost)
{
await TestInMethodAsync(@"
_ = x switch
{
[var start, .. var end] => 1
}",
testHost,
Identifier("_"),
Operators.Equals,
Identifier("x"),
ControlKeyword("switch"),
Punctuation.OpenCurly,
Punctuation.OpenBracket,
Keyword("var"),
Identifier("start"),
Punctuation.Comma,
Punctuation.DotDot,
Keyword("var"),
Identifier("end"),
Punctuation.CloseBracket,
Operators.EqualsGreaterThan,
Number("1"),
Punctuation.CloseCurly);
}

[Theory]
[CombinatorialData]
[WorkItem(18956, "https://github.com/dotnet/roslyn/issues/18956")]
public async Task TestVarPattern(TestHost testHost)
{
await TestInMethodAsync(@"
_ = 1 is var x;
",
testHost,
Identifier("_"),
Operators.Equals,
Number("1"),
Keyword("is"),
Keyword("var"),
Identifier("x"),
Punctuation.Semicolon);
}

[Theory]
[CombinatorialData]
public async Task TestTupleTypeSyntax(TestHost testHost)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public override string ToString()
return "Punctuation.OpenParen";
case ")":
return "Punctuation.CloseParen";
case "[":
return "Punctuation.OpenBracket";
case "]":
return "Punctuation.CloseBracket";
case "{":
return "Punctuation.OpenCurly";
case "}":
Expand All @@ -73,6 +77,8 @@ public override string ToString()
return "Punctuation.Colon";
case ",":
return "Punctuation.Comma";
case "..":
return "Punctuation.DotDot";
}

goto default;
Expand All @@ -84,10 +90,15 @@ public override string ToString()
return "Operators.Equals";
case "++":
return "Operators.PlusPlus";
case "=>":
return "Operators.EqualsGreaterThan";
}

goto default;

case "keyword - control":
return $"ControlKeyword(\"{Text}\")";

default:
return $"{Capitalize(ClassificationName)}(\"{Text}\")";
}
Expand Down