Skip to content

Commit 8e578c0

Browse files
committed
Fix this always failing as Roslyn adds spaces between generics which cecil doesn't
1 parent f0960aa commit 8e578c0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/SMAPI.ModBuildConfig.Analyzer.Tests/ContentManagerAnalyzerTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ public void Entry()
3333
}
3434
";
3535

36+
const string SampleUnrelatedGoodProgram = @"
37+
using System;
38+
using System.Collections.Generic;
39+
40+
namespace Sample;
41+
class Loader
42+
{
43+
public T Load<T>(string arg)
44+
{
45+
return default(T);
46+
}
47+
}
48+
class ModEntry
49+
{
50+
public void Entry()
51+
{
52+
var loader = new Loader();
53+
var test = loader.Load<Dictionary<int,string>>(""Data\Fish"");
54+
}
55+
}
56+
";
57+
3658
/// <summary>The line number where the unit tested code is injected into <see cref="SampleProgram"/>.</summary>
3759
private const int SampleCodeLine = 14;
3860

@@ -77,6 +99,15 @@ public void BadType_RaisesDiagnostic(string codeText, int column, string assetNa
7799
this.VerifyCSharpDiagnostic(code, expected);
78100
}
79101

102+
[TestCase("Game1.content.Load<Dictionary<string, string>>(\"Data\\\\Fish\");", true)]
103+
[TestCase(SampleUnrelatedGoodProgram, false)]
104+
105+
public void ValidCode_HasNoDiagnostics(string codeText, bool useWrapper)
106+
{
107+
string code = useWrapper ? SampleProgram.Replace("{{test-code}}", codeText) : codeText;
108+
this.VerifyCSharpDiagnostic(code);
109+
}
110+
80111

81112
/*********
82113
** Helpers

src/SMAPI.ModBuildConfig.Analyzer/ContentManagerAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private void AnalyzeContentManagerLoads(SyntaxNodeAnalysisContext context)
7474
string assetName = invocation.ArgumentList.Arguments[0].ToString().Replace("\"", "").Replace("\\\\", "\\");
7575

7676
var formatter = new SymbolDisplayFormat(typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters);
77-
string genericArgument = context.SemanticModel.GetTypeInfo((memberAccess.Name as GenericNameSyntax).TypeArgumentList.Arguments[0]).Type.ToDisplayString(formatter);
77+
string genericArgument = context.SemanticModel.GetTypeInfo((memberAccess.Name as GenericNameSyntax).TypeArgumentList.Arguments[0]).Type.ToDisplayString(formatter).Replace(" ", "");
7878

7979
if (this.OneSixRules.AssetMap.TryGetValue(assetName, out string expectedType))
8080
{

0 commit comments

Comments
 (0)