Skip to content

Commit 587aeae

Browse files
committed
Revamp the PermissiveAssertClass to actually work. The original implementation was broken as it would have passed assertions due to incorrect branching. Furthermore, make the comparer use the VarCmp function. To handle edge cases where conversions are involved, variant must be changed to same type before comparing.
1 parent 017b8aa commit 587aeae

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

Rubberduck.Main/ComClientLibrary/UnitTesting/PermissiveAssertClass.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ public class PermissiveAssertClass : AssertClass
3131
/// </remarks>
3232
public override void AreEqual(object expected, object actual, string message = "")
3333
{
34-
// vbNullString is marshalled as null. assume value semantics:
35-
expected = expected ?? string.Empty;
36-
actual = actual ?? string.Empty;
37-
38-
if (!PermissiveComparer.Equals(expected, actual))
34+
if (PermissiveComparer.Equals(expected, actual))
35+
{
36+
AssertHandler.OnAssertSucceeded();
37+
}
38+
else
3939
{
4040
AssertHandler.OnAssertFailed(message);
4141
}
42-
AssertHandler.OnAssertSucceeded();
4342
}
4443

4544
public override void AreNotEqual(object expected, object actual, string message = "")

Rubberduck.UnitTesting/ComClientHelpers/PermissiveObjectComparer.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,7 @@ public class PermissiveObjectComparer : IEqualityComparer<object>
1414
/// <returns>VBA equity</returns>
1515
public new bool Equals(object x, object y)
1616
{
17-
if (x == null)
18-
{
19-
return y == null;
20-
}
21-
22-
if (y == null)
23-
{
24-
return false;
25-
}
26-
27-
var converted = VariantConverter.ChangeType(y, x.GetType());
28-
29-
return x.Equals(converted);
17+
return VariantComparer.Compare(x, y) == VariantComparisonResults.VARCMP_EQ;
3018
}
3119

3220
/// <summary>

0 commit comments

Comments
 (0)