Files
Misaki.HighPerformance/Misaki.HighPerformance.Analyzer/Misaki.HighPerformance.Analyzer.Test/MisakiHighPerformanceAnalyzerUnitTests.cs
Misaki 27dfa67784
Some checks failed
Publish NuGet Packages / publish (pull_request) Has been cancelled
Add Roslyn analyzer and code fix for unique ownership
Introduce a Roslyn analyzer to enforce unique ownership semantics for structs marked with the `[NonCopyable]` attribute. Added a corresponding code fix to resolve violations by suggesting the use of `Share()` or other ownership transfer methods.

Key changes:
- Added `StructCopyCodeAnalyzer` to detect invalid struct copies.
- Implemented `StructCopyCodeFixProvider` to provide code fixes.
- Created `Misaki.HighPerformance.Analyzer` and `CodeFixes` projects.
- Added unit tests for the analyzer and code fixes.
- Introduced `UniquePtr<T>` and `SharedPtr<T>` for pointer ownership.
- Added a Visual Studio extension project and packaging support.
- Updated `UnsafeUtility` to use `nint`/`nuint` for indices.
2025-11-22 18:20:03 +09:00

60 lines
1.6 KiB
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
using VerifyCS = Misaki.HighPerformance.Analyzer.Test.CSharpCodeFixVerifier<
Misaki.HighPerformance.Analyzer.MisakiHighPerformanceAnalyzerAnalyzer,
Misaki.HighPerformance.Analyzer.MisakiHighPerformanceAnalyzerCodeFixProvider>;
namespace Misaki.HighPerformance.Analyzer.Test
{
[TestClass]
public class MisakiHighPerformanceAnalyzerUnitTest
{
//No diagnostics expected to show up
[TestMethod]
public async Task TestMethod1()
{
var test = @"";
await VerifyCS.VerifyAnalyzerAsync(test);
}
//Diagnostic and CodeFix both triggered and checked for
[TestMethod]
public async Task TestMethod2()
{
var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class {|#0:TypeName|}
{
}
}";
var fixtest = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TYPENAME
{
}
}";
var expected = VerifyCS.Diagnostic("MisakiHighPerformanceAnalyzer").WithLocation(0).WithArguments("TypeName");
await VerifyCS.VerifyCodeFixAsync(test, expected, fixtest);
}
}
}