Skip to content

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sailro committed Oct 28, 2024
1 parent 7e1ea3c commit 1043797
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Microsoft.Unity.Analyzers.Tests/EmptyUnityMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,48 @@ private void Foo()
const string fixedTest = @"
using UnityEngine;
class Camera : MonoBehaviour
{
private void Foo()
{
}
}
";
await VerifyCSharpFixAsync(test, fixedTest);
}

[Fact]
public async Task AwaitableEmptyFixedUpdate()
{
const string test = @"
using UnityEngine;
class Camera : MonoBehaviour
{
// comment expected to be removed
private async Awaitable FixedUpdate()
{
}
private void Foo()
{
}
}
";
var context = AnalyzerVerificationContext
.Default
.WithAnalyzerFilter("CS1998");

var diagnostic = ExpectDiagnostic()
.WithLocation(7, 29)
.WithArguments("FixedUpdate");

await VerifyCSharpDiagnosticAsync(context, test, diagnostic);

const string fixedTest = @"
using UnityEngine;
class Camera : MonoBehaviour
{
Expand Down
79 changes: 79 additions & 0 deletions src/Microsoft.Unity.Analyzers.Tests/ImproperMessageCaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,43 @@ private void Update()
await VerifyCSharpFixAsync(test, fixedTest);
}

[Fact]
public async Task ImproperlyCasedAwaitableUpdate()
{
const string test = @"
using UnityEngine;
class Camera : MonoBehaviour
{
private async Awaitable UPDATE()
{
}
}
";

var context = AnalyzerVerificationContext
.Default
.WithAnalyzerFilter("CS1998");

var diagnostic = ExpectDiagnostic()
.WithLocation(6, 29)
.WithArguments("UPDATE");

await VerifyCSharpDiagnosticAsync(context, test, diagnostic);

const string fixedTest = @"
using UnityEngine;
class Camera : MonoBehaviour
{
private async Awaitable Update()
{
}
}
";
await VerifyCSharpFixAsync(test, fixedTest);
}

[Fact]
public async Task ImproperlyCasedStaticUpdateIgnored()
{
Expand Down Expand Up @@ -112,6 +149,48 @@ static bool OnPreGeneratingCSProjectFiles()
await VerifyCSharpFixAsync(test, fixedTest);
}

[Fact]
public async Task ImproperlyCasedAwaitableRealStaticMessage()
{
const string test = @"
using UnityEngine;
using UnityEditor;
class App : AssetPostprocessor
{
async static Awaitable<bool> OnPREGeneratingCSProjectFiles()
{
return false;
}
}
";

var context = AnalyzerVerificationContext
.Default
.WithAnalyzerFilter("CS1998");

var diagnostic = ExpectDiagnostic()
.WithLocation(7, 34)
.WithArguments("OnPREGeneratingCSProjectFiles");

await VerifyCSharpDiagnosticAsync(context, test, diagnostic);

const string fixedTest = @"
using UnityEngine;
using UnityEditor;
class App : AssetPostprocessor
{
async static Awaitable<bool> OnPreGeneratingCSProjectFiles()
{
return false;
}
}
";
await VerifyCSharpFixAsync(test, fixedTest);
}


[Fact]
public async Task ProperlyCasedOnPostprocessAllAssets()
{
Expand Down

0 comments on commit 1043797

Please sign in to comment.