-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for DiscardDesignationSyntaxWrapper
- Loading branch information
Showing
4 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
...Analyzers/StyleCop.Analyzers.Test.CSharp7/Lightup/DiscardDesignationSyntaxWrapperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// 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); | ||
} | ||
|
||
[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.NotEqual(syntaxNode.UnderscoreToken, 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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
StyleCop.Analyzers/StyleCop.Analyzers.Test/Lightup/DiscardDesignationSyntaxWrapperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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.Lightup | ||
{ | ||
using System; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
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); | ||
} | ||
|
||
[Fact] | ||
public void TestIsInstance() | ||
{ | ||
Assert.False(DiscardDesignationSyntaxWrapper.IsInstance(null)); | ||
Assert.False(DiscardDesignationSyntaxWrapper.IsInstance(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression))); | ||
} | ||
|
||
[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 TestInvalidConversion() | ||
{ | ||
var syntaxNode = SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression); | ||
Assert.Throws<InvalidCastException>(() => (DiscardDesignationSyntaxWrapper)syntaxNode); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters