Skip to content

Commit

Permalink
Adding tests for tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
lookbusy1344 committed Oct 8, 2023
1 parent aeb2639 commit 456baf4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
26 changes: 26 additions & 0 deletions RecordValueAnalyser.Test/UnitTestsClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,30 @@ public record class A(int I, string S, IReadOnlyList<int> Fail)

await VerifyCS.VerifyAnalyzerAsync(test);
}

[TestMethod]
public async Task RecordWithTuplePass()
{
// Tuple are find if they contain value types
const string test = coGeneral
+ """
public record class Tup1(int IPass, (int a, int b) TupPass, DateTime? DtPass);
public record class Tup2(int IPass, (bool, int) TupPass);
""";

await VerifyCS.VerifyAnalyzerAsync(test);
}

[TestMethod]
public async Task RecordWithTupleFail()
{
// A tuple containing an array is not ok
const string test = coGeneral + "public record class Tup(int IPass, (int a, int[] b) TupFail);";

var expected = VerifyCS.Diagnostic("JSV01")
.WithSpan(6, 36, 6, 60)
.WithArguments("(int a, int[] b) TupFail (int[])");

await VerifyCS.VerifyAnalyzerAsync(test, expected);
}
}
28 changes: 27 additions & 1 deletion RecordValueAnalyser.Test/UnitTestsStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public record struct A(int I, string S, DateTime Dt, ClassA Ca);
}

[TestMethod]
public async Task RecordEqualsMethod()
public async Task RecordEqualsMethodPass()
{
// If the record has an Equals method, it's ok
const string test = coGeneral
Expand All @@ -173,4 +173,30 @@ public readonly record struct A(int I, string S, IReadOnlyList<int> Fail)

await VerifyCS.VerifyAnalyzerAsync(test);
}

[TestMethod]
public async Task RecordWithTuplePass()
{
// Tuple are find if they contain value types
const string test = coGeneral
+ """
public record struct Tup1(int IPass, (int a, int b) TupPass, DateTime? DtPass);
public record struct Tup2(int IPass, (bool, int) TupPass);
""";

await VerifyCS.VerifyAnalyzerAsync(test);
}

[TestMethod]
public async Task RecordWithTupleFail()
{
// A tuple containing an array is not ok
const string test = coGeneral + "public record struct Tup(int IPass, (int a, int[] b) TupFail);";

var expected = VerifyCS.Diagnostic("JSV01")
.WithSpan(6, 37, 6, 61)
.WithArguments("(int a, int[] b) TupFail (int[])");

await VerifyCS.VerifyAnalyzerAsync(test, expected);
}
}

0 comments on commit 456baf4

Please sign in to comment.