Skip to content

Commit

Permalink
SE - Nullable: Add UTs for Debug.Assert
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-mikula-sonarsource committed Mar 20, 2023
1 parent 7d8ae7d commit 4f21f86
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -750,11 +750,17 @@ public void Invocation_InformationIsNothing_NoTrackedSymbol()
}

[DataTestMethod]
[DataRow("arg != null")]
[DataRow("arg is not null")]
[DataRow("arg is { }")]
public void Invocation_DebugAssert_LearnsNotNull_Simple(string expression) =>
DebugAssertValues(expression).Should().HaveCount(1).And.ContainSingle(x => x.HasConstraint(ObjectConstraint.NotNull));
[DataRow("arg != null", "object")]
[DataRow("arg != null", "int?")]
[DataRow("arg != null", "bool?")]
[DataRow("arg is not null", "object")]
[DataRow("arg is not null", "int?")]
[DataRow("arg is not null", "bool?")]
[DataRow("arg is { }", "object")]
[DataRow("arg is { }", "int?")]
[DataRow("arg is { }", "bool?")]
public void Invocation_DebugAssert_LearnsNotNull_Simple(string expression, string argType) =>
DebugAssertValues(expression, argType).Should().SatisfyRespectively(x => x.Should().HaveOnlyConstraint(ObjectConstraint.NotNull));

[TestMethod]
public void Invocation_DebugAssert_LearnsNotNull_AndAlso() =>
Expand Down Expand Up @@ -823,6 +829,18 @@ public static void Assert() { }
new SETestContext(code, AnalyzerLanguage.CSharp, Array.Empty<SymbolicCheck>()).Validator.ValidateTagOrder("End");
}

[DataTestMethod]
[DataRow("int?")]
[DataRow("bool?")]
public void Invocation_DebugAssert_NullableHasValue_Simple(string argType) =>
DebugAssertValues("arg.HasValue", argType).Should().SatisfyRespectively(x => x.Should().HaveOnlyConstraint(ObjectConstraint.NotNull));

[DataTestMethod]
[DataRow("int?")]
[DataRow("bool?")]
public void Invocation_DebugAssert_NullableHasValue_Binary(string argType) =>
DebugAssertValues("arg.HasValue == true", argType).Should().SatisfyRespectively(x => x.Should().HaveOnlyConstraint(ObjectConstraint.NotNull));

private static SymbolicValue[] DebugAssertValues(string expression, string argType = "object")
{
var code = $@"
Expand Down

0 comments on commit 4f21f86

Please sign in to comment.