Skip to content

Commit

Permalink
Fix this always failing as Roslyn adds spaces between generics which …
Browse files Browse the repository at this point in the history
…cecil doesn't
  • Loading branch information
SinZ163 committed Nov 12, 2023
1 parent f0960aa commit 8e578c0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ public void Entry()
}
";

const string SampleUnrelatedGoodProgram = @"
using System;
using System.Collections.Generic;
namespace Sample;
class Loader
{
public T Load<T>(string arg)
{
return default(T);
}
}
class ModEntry
{
public void Entry()
{
var loader = new Loader();
var test = loader.Load<Dictionary<int,string>>(""Data\Fish"");
}
}
";

/// <summary>The line number where the unit tested code is injected into <see cref="SampleProgram"/>.</summary>
private const int SampleCodeLine = 14;

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

[TestCase("Game1.content.Load<Dictionary<string, string>>(\"Data\\\\Fish\");", true)]
[TestCase(SampleUnrelatedGoodProgram, false)]

public void ValidCode_HasNoDiagnostics(string codeText, bool useWrapper)
{
string code = useWrapper ? SampleProgram.Replace("{{test-code}}", codeText) : codeText;
this.VerifyCSharpDiagnostic(code);
}


/*********
** Helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void AnalyzeContentManagerLoads(SyntaxNodeAnalysisContext context)
string assetName = invocation.ArgumentList.Arguments[0].ToString().Replace("\"", "").Replace("\\\\", "\\");

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

if (this.OneSixRules.AssetMap.TryGetValue(assetName, out string expectedType))
{
Expand Down

0 comments on commit 8e578c0

Please sign in to comment.