Skip to content

Commit

Permalink
Add tests for DiscardDesignationSyntaxWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed May 30, 2017
1 parent 3a784a1 commit 4b84cd3
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
<Compile Include="Lightup\ConstructorDeclarationSyntaxExtensionsTests.cs" />
<Compile Include="Lightup\DeclarationPatternSyntaxWrapperTests.cs" />
<Compile Include="Lightup\DestructorDeclarationSyntaxExtensionsTests.cs" />
<Compile Include="Lightup\DiscardDesignationSyntaxWrapperTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
<Compile Include="Lightup\ConstructorDeclarationSyntaxExtensionsTests.cs" />
<Compile Include="Lightup\DeclarationPatternSyntaxWrapperTests.cs" />
<Compile Include="Lightup\DestructorDeclarationSyntaxExtensionsTests.cs" />
<Compile Include="Lightup\DiscardDesignationSyntaxWrapperTests.cs" />
<Compile Include="LinqHelpers\SyntaxTriviaListEnumerableTests.cs" />
<Compile Include="MaintainabilityRules\DebugMessagesUnitTestsBase.cs" />
<Compile Include="MaintainabilityRules\FileMayOnlyContainTestBase.cs" />
Expand Down

0 comments on commit 4b84cd3

Please sign in to comment.