DeepEqual icon indicating copy to clipboard operation
DeepEqual copied to clipboard

Default comparison of enums

Open hwanders opened this issue 5 years ago • 0 comments

It seems that by default instances of different enum types are never evaluated as deep-equal, even if their names match.

I have to apply SkipDefault<EnumType1>().SkipDefault<EnumType2>() or WithCustomComparison(new EnumComparison()) to get a working comparison.

Is this the intended behavior?

public enum Foo { X = 1, Y = 2 } 
public enum Bar { X = 1, Y = 2 }

[Test]
public void Enums_WithSameName_ShouldDeepEqual()
{
    // throws with Actual != Expected (X != X)
    (Foo.X).ShouldDeepEqual(Bar.X);
}

[Test]
public void Enums_WithSameName_WithDeepEqualAndSkipTypes_ShouldAssert()
{
    // works (and successfully throws when comparing Foo.X with Bar.Y)
    (Foo.X).WithDeepEqual(Bar.X).SkipDefault<Foo>().SkipDefault<Bar>().Assert();
}

[Test]
public void Enums_WithSameName_WithCustomComparison_ShouldAssert()
{
    // works (and successfully throws when comparing Foo.X with Bar.Y)
    (Foo.X).WithDeepEqual(Bar.X).WithCustomComparison(new EnumComparison()).Assert();
}

hwanders avatar Apr 01 '20 09:04 hwanders