Skip to content

Commit 056110d

Browse files
committed
Update SyntaxWrapperHelperTests
1 parent 5157250 commit 056110d

5 files changed

Lines changed: 66 additions & 28 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.Lightup
5+
{
6+
using StyleCop.Analyzers.Test.Lightup;
7+
8+
public class SyntaxWrapperHelperTestsCSharp7 : SyntaxWrapperHelperTests
9+
{
10+
}
11+
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/Lightup/WrapperHelperTests.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Lightup/WrapperHelperTestsCSharp8.cs renamed to StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Lightup/SyntaxWrapperHelperTestsCSharp8.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace StyleCop.Analyzers.Test.CSharp8.Lightup
55
{
66
using StyleCop.Analyzers.Test.CSharp7.Lightup;
77

8-
public class WrapperHelperTestsCSharp8 : WrapperHelperTests
8+
public class SyntaxWrapperHelperTestsCSharp8 : SyntaxWrapperHelperTestsCSharp7
99
{
1010
}
1111
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/Lightup/WrapperHelperTestsCSharp9.cs renamed to StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/Lightup/SyntaxWrapperHelperTestsCSharp9.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace StyleCop.Analyzers.Test.CSharp9.Lightup
55
{
66
using StyleCop.Analyzers.Test.CSharp8.Lightup;
77

8-
public class WrapperHelperTestsCSharp9 : WrapperHelperTestsCSharp8
8+
public class SyntaxWrapperHelperTestsCSharp9 : SyntaxWrapperHelperTestsCSharp8
99
{
1010
}
1111
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.Lightup
5+
{
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Reflection;
10+
using Microsoft.CodeAnalysis.CSharp;
11+
using Microsoft.CodeAnalysis.CSharp.Syntax;
12+
using StyleCop.Analyzers.Lightup;
13+
using Xunit;
14+
15+
public class SyntaxWrapperHelperTests
16+
{
17+
public static IEnumerable<object[]> SyntaxWrapperClasses
18+
{
19+
get
20+
{
21+
var wrapperTypes = typeof(ISyntaxWrapper<>).Assembly.GetTypes()
22+
.Where(t => t.GetTypeInfo().ImplementedInterfaces.Any(i => i.IsGenericType && (i.GetGenericTypeDefinition() == typeof(ISyntaxWrapper<>))));
23+
24+
foreach (var wrapperType in wrapperTypes)
25+
{
26+
yield return new object[] { wrapperType };
27+
}
28+
}
29+
}
30+
31+
[Theory]
32+
[MemberData(nameof(SyntaxWrapperClasses))]
33+
public void VerifyThatWrapperClassIsPresent(Type wrapperType)
34+
{
35+
var wrappedTypeName = $"Microsoft.CodeAnalysis.CSharp.Syntax.{wrapperType.Name.Substring(0, wrapperType.Name.Length - "Wrapper".Length)}";
36+
if (typeof(CSharpSyntaxNode).Assembly.GetType(wrappedTypeName) is { } expected)
37+
{
38+
var wrappedType = SyntaxWrapperHelper.GetWrappedType(wrapperType);
39+
Assert.Same(expected, wrappedType);
40+
}
41+
else if (wrapperType == typeof(CommonForEachStatementSyntaxWrapper))
42+
{
43+
// Special case for C# 6 analysis compatibility
44+
Assert.False(LightupHelpers.SupportsCSharp7);
45+
Assert.Same(typeof(ForEachStatementSyntax), SyntaxWrapperHelper.GetWrappedType(wrapperType));
46+
}
47+
else
48+
{
49+
Assert.Null(SyntaxWrapperHelper.GetWrappedType(wrapperType));
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)