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

Support C# 7 via light-up #2370

Merged
merged 31 commits into from
Jun 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
00da276
Support expression-bodied accessors via light-up
sharwell May 29, 2017
82212f3
Support PatternSyntax and derived types via light-up
sharwell May 29, 2017
a043f15
Add test project for C# 7 syntax
sharwell May 30, 2017
f48250c
Add initial tests for AccessorDeclarationSyntaxExtensions
sharwell May 30, 2017
137e535
Add tests for remaining expression-bodied members
sharwell May 30, 2017
0a556b2
Add tests for ConstantPatternSyntaxWrapper
sharwell May 30, 2017
307b465
Add tests for DeclarationPatternSyntaxWrapper
sharwell May 30, 2017
3a784a1
Add additional tests covering SyntaxKindEx features
sharwell May 30, 2017
4b84cd3
Add tests for DiscardDesignationSyntaxWrapper
sharwell May 30, 2017
ca41a26
Add tests for PatternSyntaxWrapper
sharwell May 30, 2017
6fc993f
Add tests for VariableDesignationSyntaxWrapper
sharwell May 30, 2017
e6a3b9a
Improved handling of token comparisons in tests
sharwell May 30, 2017
e441f6b
Add tests for SingleVariableDesignationSyntaxWrapper
sharwell May 30, 2017
fdc0ca8
Add tests for ParenthesizedVariableDesignationSyntaxWrapper
sharwell May 30, 2017
afb97e4
Exclude some unnecessary features from the light-up checklist
sharwell May 30, 2017
ed8974f
Implement light-up support for SeparatedSyntaxList<T>
sharwell May 30, 2017
d87b921
Add tests for SyntaxWrapper<T> and LightupHelpers
sharwell May 30, 2017
45e0f02
Add initial tests for SeparatedSyntaxListWrapper<T>
sharwell May 30, 2017
9168ce9
Add light-up support for CasePatternSwitchLabelSyntax and WhenClauseS…
sharwell May 31, 2017
1cacccf
Add light-up support for RefExpressionSyntax and RefTypeSyntax
sharwell May 31, 2017
ea7e825
Add light-up support for ThrowExpressionSyntax
sharwell May 31, 2017
419dd52
Add light up support for tuples
sharwell May 31, 2017
5a53f10
Add ParenthesizedVariableDesignationSyntaxWrapper.AddVariables
sharwell Jun 4, 2017
e6cb406
Add light-up support for CommonForEachStatementSyntax and derived
sharwell Jun 9, 2017
2f9db03
Add light-up support for DeclarationExpressionSyntax
sharwell Jun 9, 2017
de9da19
Add light-up support for IsPatternExpressionSyntax
sharwell Jun 9, 2017
640bb9b
Add light-up support for local functions
sharwell Jun 9, 2017
32f3a7c
Make SyntaxKindEx a static class with SyntaxKind constants
sharwell Jun 9, 2017
28f136e
Add light-up constants for additional enum members added in C# 7
sharwell Jun 9, 2017
c31beae
Add tests for IsPatternExpressionSyntaxWrapper
sharwell Jun 10, 2017
1147f65
Fix broken test (comparing SyntaxNode identity to a wrapper)
sharwell Jun 10, 2017
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 @@ -40,4 +40,5 @@
[assembly: AssemblyInformationalVersion("1.1.0-dev")]

[assembly: InternalsVisibleTo("StyleCop.Analyzers.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c36d40d996fcc95fb6a89754728616758f459026e31478ce93633b3e27a4af416f103aa3d7a9e7998f829f8715cc1240d30724fd662042550fa71357b19562622424267e9e4640c403edbe64709a9ca5918128a9b9020b0db6e770d0dd1eac888869c23a835b74bde00e171984b1d1c24636cf030f0b23106e73035a2be145a6")]
[assembly: InternalsVisibleTo("StyleCop.Analyzers.Test.CSharp7, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c36d40d996fcc95fb6a89754728616758f459026e31478ce93633b3e27a4af416f103aa3d7a9e7998f829f8715cc1240d30724fd662042550fa71357b19562622424267e9e4640c403edbe64709a9ca5918128a9b9020b0db6e770d0dd1eac888869c23a835b74bde00e171984b1d1c24636cf030f0b23106e73035a2be145a6")]
[assembly: InternalsVisibleTo("StyleCopTester, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c36d40d996fcc95fb6a89754728616758f459026e31478ce93633b3e27a4af416f103aa3d7a9e7998f829f8715cc1240d30724fd662042550fa71357b19562622424267e9e4640c403edbe64709a9ca5918128a9b9020b0db6e770d0dd1eac888869c23a835b74bde00e171984b1d1c24636cf030f0b23106e73035a2be145a6")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.Test.CSharp7.Lightup
{
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Lightup;
using Xunit;

public class AccessorDeclarationSyntaxExtensionsTests
{
[Fact]
public void TestExpressionBody()
{
var accessorDeclarationSyntax = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
.WithExpressionBody(SyntaxFactory.ArrowExpressionClause(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)));
Assert.Same(accessorDeclarationSyntax.ExpressionBody, AccessorDeclarationSyntaxExtensions.ExpressionBody(accessorDeclarationSyntax));
}

[Fact]
public void TestWithExpressionBody()
{
var accessorDeclarationSyntax = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration);
var expressionBody = SyntaxFactory.ArrowExpressionClause(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression));
var accessorWithBody = AccessorDeclarationSyntaxExtensions.WithExpressionBody(accessorDeclarationSyntax, expressionBody);
Assert.Null(accessorDeclarationSyntax.ExpressionBody);
Assert.NotNull(accessorWithBody.ExpressionBody);
Assert.Equal(SyntaxKind.NullLiteralExpression, accessorWithBody.ExpressionBody.Expression.Kind());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.Test.CSharp7.Lightup
{
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Lightup;
using Xunit;

public class BaseMethodDeclarationSyntaxExtensionsTests
{
[Fact]
public void TestExpressionBody()
{
var syntax = SyntaxFactory.ConstructorDeclaration(SyntaxFactory.Identifier("Anything"))
.WithExpressionBody(SyntaxFactory.ArrowExpressionClause(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)));
Assert.Same(syntax.ExpressionBody, BaseMethodDeclarationSyntaxExtensions.ExpressionBody(syntax));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.Test.CSharp7.Lightup
{
using System;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Helpers;
using StyleCop.Analyzers.Lightup;
using Xunit;

public class ConstantPatternSyntaxWrapperTests
{
[Fact]
public void TestNull()
{
var syntaxNode = default(SyntaxNode);
var constantPatternSyntax = (ConstantPatternSyntaxWrapper)syntaxNode;
Assert.Null(constantPatternSyntax.SyntaxNode);
Assert.Throws<NullReferenceException>(() => constantPatternSyntax.Expression);
Assert.Throws<NullReferenceException>(() => constantPatternSyntax.WithExpression(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)));
}

[Fact]
public void TestExpression()
{
var syntaxNode = SyntaxFactory.ConstantPattern(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression));
Assert.True(syntaxNode.IsKind(SyntaxKind.ConstantPattern));
Assert.True(syntaxNode.IsKind(SyntaxKindEx.ConstantPattern));

var constantPatternSyntax = (ConstantPatternSyntaxWrapper)syntaxNode;
Assert.Same(syntaxNode, constantPatternSyntax.SyntaxNode);
Assert.Same(syntaxNode.Expression, constantPatternSyntax.Expression);

constantPatternSyntax = constantPatternSyntax.WithExpression(SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(1)));
Assert.NotNull(constantPatternSyntax.SyntaxNode);
Assert.NotSame(syntaxNode, constantPatternSyntax.SyntaxNode);
Assert.Equal(SyntaxKind.NumericLiteralExpression, constantPatternSyntax.Expression.Kind());
}

[Fact]
public void TestIsInstance()
{
Assert.False(ConstantPatternSyntaxWrapper.IsInstance(null));
Assert.False(ConstantPatternSyntaxWrapper.IsInstance(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)));

var syntaxNode = SyntaxFactory.ConstantPattern(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression));
Assert.True(ConstantPatternSyntaxWrapper.IsInstance(syntaxNode));
}

[Fact]
public void TestConversionsNull()
{
var syntaxNode = default(SyntaxNode);
var constantPatternSyntax = (ConstantPatternSyntaxWrapper)syntaxNode;

PatternSyntaxWrapper patternSyntax = constantPatternSyntax;
Assert.Null(patternSyntax.SyntaxNode);

constantPatternSyntax = (ConstantPatternSyntaxWrapper)patternSyntax;
Assert.Null(constantPatternSyntax.SyntaxNode);

SyntaxNode syntax = constantPatternSyntax;
Assert.Null(syntax);
}

[Fact]
public void TestConversions()
{
var syntaxNode = SyntaxFactory.ConstantPattern(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression));
var constantPatternSyntax = (ConstantPatternSyntaxWrapper)syntaxNode;

PatternSyntaxWrapper patternSyntax = constantPatternSyntax;
Assert.Same(syntaxNode, patternSyntax.SyntaxNode);

constantPatternSyntax = (ConstantPatternSyntaxWrapper)patternSyntax;
Assert.Same(syntaxNode, constantPatternSyntax.SyntaxNode);

SyntaxNode syntax = constantPatternSyntax;
Assert.Same(syntaxNode, syntax);
}

[Fact]
public void TestInvalidConversion()
{
var syntaxNode = SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression);
Assert.Throws<InvalidCastException>(() => (ConstantPatternSyntaxWrapper)syntaxNode);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.Test.CSharp7.Lightup
{
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Lightup;
using Xunit;

public class ConstructorDeclarationSyntaxExtensionsTests
{
[Fact]
public void TestWithExpressionBody()
{
var syntax = SyntaxFactory.ConstructorDeclaration(SyntaxFactory.Identifier("Anything"));
var expressionBody = SyntaxFactory.ArrowExpressionClause(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression));
var syntaxWithBody = ConstructorDeclarationSyntaxExtensions.WithExpressionBody(syntax, expressionBody);
Assert.Null(syntax.ExpressionBody);
Assert.NotNull(syntaxWithBody.ExpressionBody);
Assert.Equal(SyntaxKind.NullLiteralExpression, syntaxWithBody.ExpressionBody.Expression.Kind());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.Test.CSharp7.Lightup
{
using System;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using StyleCop.Analyzers.Helpers;
using StyleCop.Analyzers.Lightup;
using Xunit;

public class DeclarationPatternSyntaxWrapperTests
{
[Fact]
public void TestNull()
{
var syntaxNode = default(SyntaxNode);
var declarationPatternSyntax = (DeclarationPatternSyntaxWrapper)syntaxNode;
Assert.Null(declarationPatternSyntax.SyntaxNode);
Assert.Throws<NullReferenceException>(() => declarationPatternSyntax.Type);
Assert.Throws<NullReferenceException>(() => declarationPatternSyntax.Designation);
Assert.Throws<NullReferenceException>(() => declarationPatternSyntax.WithType(SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.IntKeyword))));
Assert.Throws<NullReferenceException>(() => declarationPatternSyntax.WithDesignation((VariableDesignationSyntaxWrapper)SyntaxFactory.DiscardDesignation()));
}

[Fact]
public void TestProperties()
{
var syntaxNode = SyntaxFactory.DeclarationPattern(
SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.IntKeyword)),
SyntaxFactory.DiscardDesignation());
Assert.True(syntaxNode.IsKind(SyntaxKind.DeclarationPattern));
Assert.True(syntaxNode.IsKind(SyntaxKindEx.DeclarationPattern));

var declarationPatternSyntax = (DeclarationPatternSyntaxWrapper)syntaxNode;
Assert.Same(syntaxNode, declarationPatternSyntax.SyntaxNode);
Assert.Same(syntaxNode.Type, declarationPatternSyntax.Type);
Assert.Same(syntaxNode.Designation, declarationPatternSyntax.Designation.SyntaxNode);

declarationPatternSyntax = declarationPatternSyntax.WithType(SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.IntKeyword)));
Assert.NotNull(declarationPatternSyntax.SyntaxNode);
Assert.NotSame(syntaxNode, declarationPatternSyntax.SyntaxNode);
Assert.Same(((DeclarationPatternSyntax)declarationPatternSyntax.SyntaxNode).Type, declarationPatternSyntax.Type);

declarationPatternSyntax = declarationPatternSyntax.WithDesignation((VariableDesignationSyntaxWrapper)SyntaxFactory.SingleVariableDesignation(SyntaxFactory.Identifier("Anything")));
Assert.NotNull(declarationPatternSyntax.SyntaxNode);
Assert.NotSame(syntaxNode, declarationPatternSyntax.SyntaxNode);
Assert.Same(((DeclarationPatternSyntax)declarationPatternSyntax.SyntaxNode).Designation, declarationPatternSyntax.Designation.SyntaxNode);
}

[Fact]
public void TestIsInstance()
{
Assert.False(DeclarationPatternSyntaxWrapper.IsInstance(null));
Assert.False(DeclarationPatternSyntaxWrapper.IsInstance(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)));

var syntaxNode = SyntaxFactory.DeclarationPattern(
SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.IntKeyword)),
SyntaxFactory.DiscardDesignation());
Assert.True(DeclarationPatternSyntaxWrapper.IsInstance(syntaxNode));
}

[Fact]
public void TestConversionsNull()
{
var syntaxNode = default(SyntaxNode);
var declarationPatternSyntax = (DeclarationPatternSyntaxWrapper)syntaxNode;

PatternSyntaxWrapper patternSyntax = declarationPatternSyntax;
Assert.Null(patternSyntax.SyntaxNode);

declarationPatternSyntax = (DeclarationPatternSyntaxWrapper)patternSyntax;
Assert.Null(declarationPatternSyntax.SyntaxNode);

SyntaxNode syntax = declarationPatternSyntax;
Assert.Null(syntax);
}

[Fact]
public void TestConversions()
{
var syntaxNode = SyntaxFactory.DeclarationPattern(
SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.IntKeyword)),
SyntaxFactory.DiscardDesignation());
var declarationPatternSyntax = (DeclarationPatternSyntaxWrapper)syntaxNode;

PatternSyntaxWrapper patternSyntax = declarationPatternSyntax;
Assert.Same(syntaxNode, patternSyntax.SyntaxNode);

declarationPatternSyntax = (DeclarationPatternSyntaxWrapper)patternSyntax;
Assert.Same(syntaxNode, declarationPatternSyntax.SyntaxNode);

SyntaxNode syntax = declarationPatternSyntax;
Assert.Same(syntaxNode, syntax);
}

[Fact]
public void TestInvalidConversion()
{
var syntaxNode = SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression);
Assert.Throws<InvalidCastException>(() => (DeclarationPatternSyntaxWrapper)syntaxNode);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.Test.CSharp7.Lightup
{
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Lightup;
using Xunit;

public class DestructorDeclarationSyntaxExtensionsTests
{
[Fact]
public void TestWithExpressionBody()
{
var syntax = SyntaxFactory.DestructorDeclaration(SyntaxFactory.Identifier("Anything"));
var expressionBody = SyntaxFactory.ArrowExpressionClause(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression));
var syntaxWithBody = DestructorDeclarationSyntaxExtensions.WithExpressionBody(syntax, expressionBody);
Assert.Null(syntax.ExpressionBody);
Assert.NotNull(syntaxWithBody.ExpressionBody);
Assert.Equal(SyntaxKind.NullLiteralExpression, syntaxWithBody.ExpressionBody.Expression.Kind());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.Test.CSharp7.Lightup
{
using System;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Helpers;
using StyleCop.Analyzers.Lightup;
using Xunit;

public class DiscardDesignationSyntaxWrapperTests
{
[Fact]
public void TestNull()
{
var syntaxNode = default(SyntaxNode);
var discardDesignationSyntax = (DiscardDesignationSyntaxWrapper)syntaxNode;
Assert.Null(discardDesignationSyntax.SyntaxNode);
Assert.Throws<NullReferenceException>(() => discardDesignationSyntax.UnderscoreToken);
Assert.Throws<NullReferenceException>(() => discardDesignationSyntax.WithUnderscoreToken(SyntaxFactory.Token(SyntaxKind.UnderscoreToken)));
}

[Fact]
public void TestUnderscoreToken()
{
var syntaxNode = SyntaxFactory.DiscardDesignation();
Assert.True(syntaxNode.IsKind(SyntaxKind.DiscardDesignation));
Assert.True(syntaxNode.IsKind(SyntaxKindEx.DiscardDesignation));

var discardDesignationSyntax = (DiscardDesignationSyntaxWrapper)syntaxNode;
Assert.Same(syntaxNode, discardDesignationSyntax.SyntaxNode);
Assert.Equal(syntaxNode.UnderscoreToken, discardDesignationSyntax.UnderscoreToken);

discardDesignationSyntax = discardDesignationSyntax.WithUnderscoreToken(SpacingExtensions.WithoutTrivia(SyntaxFactory.Token(SyntaxKind.UnderscoreToken)));
Assert.NotNull(discardDesignationSyntax.SyntaxNode);
Assert.NotSame(syntaxNode, discardDesignationSyntax.SyntaxNode);
Assert.False(syntaxNode.UnderscoreToken.IsEquivalentTo(discardDesignationSyntax.UnderscoreToken));
}

[Fact]
public void TestIsInstance()
{
Assert.False(DiscardDesignationSyntaxWrapper.IsInstance(null));
Assert.False(DiscardDesignationSyntaxWrapper.IsInstance(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)));

var syntaxNode = SyntaxFactory.DiscardDesignation();
Assert.True(DiscardDesignationSyntaxWrapper.IsInstance(syntaxNode));
}

[Fact]
public void TestConversionsNull()
{
var syntaxNode = default(SyntaxNode);
var discardDesignationSyntax = (DiscardDesignationSyntaxWrapper)syntaxNode;

VariableDesignationSyntaxWrapper variableDesignationSyntax = discardDesignationSyntax;
Assert.Null(variableDesignationSyntax.SyntaxNode);

discardDesignationSyntax = (DiscardDesignationSyntaxWrapper)variableDesignationSyntax;
Assert.Null(discardDesignationSyntax.SyntaxNode);

SyntaxNode syntax = discardDesignationSyntax;
Assert.Null(syntax);
}

[Fact]
public void TestConversions()
{
var syntaxNode = SyntaxFactory.DiscardDesignation();
var discardDesignationSyntax = (DiscardDesignationSyntaxWrapper)syntaxNode;

VariableDesignationSyntaxWrapper variableDesignationSyntax = discardDesignationSyntax;
Assert.Same(syntaxNode, variableDesignationSyntax.SyntaxNode);

discardDesignationSyntax = (DiscardDesignationSyntaxWrapper)variableDesignationSyntax;
Assert.Same(syntaxNode, discardDesignationSyntax.SyntaxNode);

SyntaxNode syntax = discardDesignationSyntax;
Assert.Same(syntaxNode, syntax);
}

[Fact]
public void TestInvalidConversion()
{
var syntaxNode = SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression);
Assert.Throws<InvalidCastException>(() => (DiscardDesignationSyntaxWrapper)syntaxNode);
}
}
}
Loading