summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.Helper.cs2
-rw-r--r--src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetFieldBase.cs16
-rw-r--r--src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetInt.cs6
-rw-r--r--src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs6
-rw-r--r--src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs18
-rw-r--r--src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs6
-rw-r--r--src/SMAPI.ModBuildConfig.Analyzer.Tests/UnitTests.cs27
7 files changed, 57 insertions, 24 deletions
diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.Helper.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.Helper.cs
index d33455fc..0247288e 100644
--- a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.Helper.cs
+++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Framework/DiagnosticVerifier.Helper.cs
@@ -20,6 +20,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
private static readonly MetadataReference SystemCoreReference = MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location);
private static readonly MetadataReference CSharpSymbolsReference = MetadataReference.CreateFromFile(typeof(CSharpCompilation).Assembly.Location);
private static readonly MetadataReference CodeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location);
+ private static readonly MetadataReference SelfReference = MetadataReference.CreateFromFile(typeof(DiagnosticVerifier).Assembly.Location);
internal static string DefaultFilePathPrefix = "Test";
internal static string CSharpDefaultFileExt = "cs";
@@ -150,6 +151,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
var solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language)
+ .AddMetadataReference(projectId, DiagnosticVerifier.SelfReference)
.AddMetadataReference(projectId, CorlibReference)
.AddMetadataReference(projectId, SystemCoreReference)
.AddMetadataReference(projectId, CSharpSymbolsReference)
diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetFieldBase.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetFieldBase.cs
new file mode 100644
index 00000000..1684229a
--- /dev/null
+++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetFieldBase.cs
@@ -0,0 +1,16 @@
+// ReSharper disable CheckNamespace -- matches Stardew Valley's code
+namespace Netcode
+{
+ /// <summary>A simplified version of Stardew Valley's <c>Netcode.NetFieldBase</c> for unit testing.</summary>
+ /// <typeparam name="T">The type of the synchronised value.</typeparam>
+ /// <typeparam name="TSelf">The type of the current instance.</typeparam>
+ public class NetFieldBase<T, TSelf> where TSelf : NetFieldBase<T, TSelf>
+ {
+ /// <summary>The synchronised value.</summary>
+ public T Value { get; set; }
+
+ /// <summary>Implicitly convert a net field to the its type.</summary>
+ /// <param name="field">The field to convert.</param>
+ public static implicit operator T(NetFieldBase<T, TSelf> field) => field.Value;
+ }
+}
diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetInt.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetInt.cs
new file mode 100644
index 00000000..b3abc467
--- /dev/null
+++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetInt.cs
@@ -0,0 +1,6 @@
+// ReSharper disable CheckNamespace -- matches Stardew Valley's code
+namespace Netcode
+{
+ /// <summary>A simplified version of Stardew Valley's <c>Netcode.NetInt</c> for unit testing.</summary>
+ public class NetInt : NetFieldBase<int, NetInt> { }
+}
diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs
new file mode 100644
index 00000000..714c4a8d
--- /dev/null
+++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs
@@ -0,0 +1,6 @@
+// ReSharper disable CheckNamespace -- matches Stardew Valley's code
+namespace Netcode
+{
+ /// <summary>A simplified version of Stardew Valley's <c>Netcode.NetRef</c> for unit testing.</summary>
+ public class NetRef : NetFieldBase<object, NetRef> { }
+}
diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs
new file mode 100644
index 00000000..88723a56
--- /dev/null
+++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs
@@ -0,0 +1,18 @@
+// ReSharper disable CheckNamespace, InconsistentNaming -- matches Stardew Valley's code
+using Netcode;
+
+namespace StardewValley
+{
+ /// <summary>A simplified version of Stardew Valley's <c>StardewValley.Item</c> class for unit testing.</summary>
+ public class Item
+ {
+ /// <summary>A net int field with an equivalent non-net <c>Category</c> property.</summary>
+ public NetInt category { get; } = new NetInt { Value = 42 };
+
+ /// <summary>A net int field with no equivalent non-net property.</summary>
+ public NetInt type { get; } = new NetInt { Value = 42 };
+
+ /// <summary>A net reference field.</summary>
+ public NetRef refField { get; } = null;
+ }
+}
diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs
new file mode 100644
index 00000000..498c38c1
--- /dev/null
+++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs
@@ -0,0 +1,6 @@
+// ReSharper disable CheckNamespace -- matches Stardew Valley's code
+namespace StardewValley
+{
+ /// <summary>A simplified version of Stardew Valley's <c>StardewValley.Object</c> class for unit testing.</summary>
+ public class Object : Item { }
+}
diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/UnitTests.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/UnitTests.cs
index f3919f78..c12bb839 100644
--- a/src/SMAPI.ModBuildConfig.Analyzer.Tests/UnitTests.cs
+++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/UnitTests.cs
@@ -18,28 +18,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests
using System;
using StardewValley;
using Netcode;
-
- namespace Netcode
- {
- public class NetInt : NetFieldBase<int, NetInt> { }
- public class NetRef : NetFieldBase<object, NetRef> { }
- public class NetFieldBase<T, TSelf> where TSelf : NetFieldBase<T, TSelf>
- {
- public T Value { get; set; }
- public static implicit operator T(NetFieldBase<T, TSelf> field) => field.Value;
- }
- }
-
- namespace StardewValley
- {
- class Item
- {
- public NetInt category { get; } = new NetInt { Value = 42 }; // SMAPI002: use Category instead
- public NetInt type { get; } = new NetInt { Value = 42 };
- public NetRef refField { get; } = null;
- }
- class SObject : Item { }
- }
+ using SObject = StardewValley.Object;
namespace SampleMod
{
@@ -51,7 +30,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests
SObject obj = null;
// this line should raise diagnostics
- {{test-code}} // line 38
+ {{test-code}}
// these lines should not
if (item.type.Value != 42);
@@ -61,7 +40,7 @@ namespace SMAPI.ModBuildConfig.Analyzer.Tests
";
/// <summary>The line number where the unit tested code is injected into <see cref="SampleProgram"/>.</summary>
- private const int SampleCodeLine = 38;
+ private const int SampleCodeLine = 17;
/// <summary>The column number where the unit tested code is injected into <see cref="SampleProgram"/>.</summary>
private const int SampleCodeColumn = 25;