Skip to content

Commit

Permalink
BH0002AnalyzerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
na1307 committed Dec 19, 2024
1 parent bd82f83 commit 3d32d32
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions Bluehill.Analyzers.Tests/BH0002AnalyzerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using Verify =
Microsoft.CodeAnalysis.CSharp.Testing.CSharpAnalyzerVerifier<Bluehill.Analyzers.BH0002FieldsShouldBeAtTheTopAnalyzer,
Microsoft.CodeAnalysis.Testing.DefaultVerifier>;

namespace Bluehill.Analyzers.Tests;

public sealed class BH0002AnalyzerTest {
[Theory]
[InlineData(
"""
public class TestClass {
public TestClass(string name) => this.name = name;
public string GetName() => name;
private readonly string [|name|];
}
"""
)]
[InlineData(
"""
public class TestClass {
private readonly string name;
public TestClass(string name) => this.name = name;
public string GetName() => name;
}
"""
)]
[InlineData(
"""
public class TestClass {
public TestClass(string name) => this.name = name;
public string GetName() => name;
[System.NonSerialized]
private readonly string [|name|];
}
"""
)]
[InlineData(
"""
public class TestClass {
[System.NonSerialized]
private readonly string name;
public TestClass(string name) => this.name = name;
public string GetName() => name;
}
"""
)]
[InlineData(
"""
public partial class TestClass {
public TestClass(string name) => this.name = name;
public string GetName() => name;
private readonly string name;
}
"""
)]
[InlineData(
"""
public record class TestClass {
public TestClass(string name) => this.name = name;
public string GetName() => name;
private readonly string name;
}
"""
)]
[InlineData(
"""
public class TestClass(string constructorName) {
public string GetName() => name;
private readonly string [|name|] = constructorName;
}
"""
)]
[InlineData(
"""
public class TestClass(string constructorName) {
private readonly string name = constructorName;
public string GetName() => name;
}
"""
)]
public Task Test(string source) => Verify.VerifyAnalyzerAsync(source);
}

0 comments on commit 3d32d32

Please sign in to comment.