Skip to content

Commit ca6a1ac

Browse files
committed
Fix unit tests
1 parent 8e578c0 commit ca6a1ac

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void EmptyCode_HasNoDiagnostics()
8282
/// <param name="expression">The expression which should be reported.</param>
8383
/// <param name="netType">The net type name which should be reported.</param>
8484
/// <param name="suggestedProperty">The suggested property name which should be reported.</param>
85-
[TestCase("Game1.content.Load<Dictionary<int, string>>(\"Data\\\\Fish\");", 0, "Data\\Fish", "System.Collections.Generic.Dictionary<System.Int32, System.String>", "System.Collections.Generic.Dictionary<System.String,System.String>")]
85+
[TestCase("Game1.content.Load<Dictionary<int, string>>(\"Data\\\\Fish\");", 0, "Data\\Fish", "System.Collections.Generic.Dictionary<System.Int32,System.String>", "System.Collections.Generic.Dictionary<System.String,System.String>")]
8686
public void BadType_RaisesDiagnostic(string codeText, int column, string assetName, string expectedType, string suggestedType)
8787
{
8888
// arrange
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace StardewValley
2+
{
3+
public class Game1
4+
{
5+
public static LocalizedContentManager content = new();
6+
}
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ReSharper disable CheckNamespace, InconsistentNaming -- matches Stardew Valley's code
2+
// ReSharper disable UnusedMember.Global -- used dynamically for unit tests
3+
namespace StardewValley
4+
{
5+
/// <summary>A simplified version of Stardew Valley's <c>StardewValley.LocalizedContentManager</c> class for unit testing.</summary>
6+
public class LocalizedContentManager
7+
{
8+
public T Load<T>(string assetName)
9+
{
10+
return default!;
11+
}
12+
}
13+
}

src/SMAPI.ModBuildConfig.Analyzer/ContentManagerAnalyzer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ private void AnalyzeContentManagerLoads(SyntaxNodeAnalysisContext context)
7070
var memberAccess = invocation.Expression as MemberAccessExpressionSyntax;
7171
if (memberAccess == null || memberAccess.Name.Identifier.ValueText != "Load")
7272
return;
73+
string? loadNamespace = context.SemanticModel.GetSymbolInfo(memberAccess).Symbol?.ContainingNamespace.Name;
74+
if (!(loadNamespace == "StardewValley" || loadNamespace == "StardewModdingAPI"))
75+
return;
7376
// "Data\\Fish" -> Data\Fish
7477
string assetName = invocation.ArgumentList.Arguments[0].ToString().Replace("\"", "").Replace("\\\\", "\\");
7578

@@ -78,6 +81,8 @@ private void AnalyzeContentManagerLoads(SyntaxNodeAnalysisContext context)
7881

7982
if (this.OneSixRules.AssetMap.TryGetValue(assetName, out string expectedType))
8083
{
84+
// delete `3 as I can't convince Roslyn and Cecil to agree
85+
// TODO: Move into DataGeneration
8186
expectedType = Regex.Replace(expectedType, "`\\d+", "");
8287
if (genericArgument != expectedType)
8388
{

0 commit comments

Comments
 (0)