Skip to content

Commit

Permalink
remove operator overrides for Eq impl
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcknight-bb committed Nov 5, 2024
1 parent 711664f commit bd9186b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
10 changes: 0 additions & 10 deletions bindgen/templates/ObjectTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ public override bool Equals(object? obj)
if (obj is null || !(obj is {{type_name}})) return false;
return Equals(obj as {{type_name}});
}
public static bool operator == ({{type_name}}? a, {{type_name}}? b)
{
if (a is null || b is null) return Object.Equals(a, b);
return a.Equals(b);
}
public static bool operator != ({{type_name}}? a, {{type_name}}? b)
{
if (a is null || b is null) return !Object.Equals(a, b);
return !(a.Equals(b));
}
{%- when UniffiTrait::Hash { hash } %}
public override int GetHashCode() {
return (int){{ Type::UInt64.borrow()|lift_fn }}({%- call cs::to_ffi_call_with_prefix("this.GetHandle()", hash) %});
Expand Down
38 changes: 18 additions & 20 deletions dotnet-tests/UniffiCS.BindingTests/TestTraitMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,17 @@ public void TestEq()
{
using (var methods = new TraitMethods("yo"))
{
// Values are equal if input is the same
Assert.Equal(methods, new TraitMethods("yo"));
Assert.True(methods == new TraitMethods("yo"));

Assert.Equal(methods, methods);

Assert.NotEqual(methods, new TraitMethods("yoyo"));
Assert.True(methods != new TraitMethods("yoyo"));
}

Assert.False(new TraitMethods("yo") == null);
// Values are not referentially equal
Assert.False(methods == new TraitMethods("yo"));
}
}

[Fact]
public void TestEqNulls()
public void TestEqNull()
{
TraitMethods? t1 = null;
TraitMethods? t2 = null;
Expand All @@ -54,8 +51,10 @@ public void TestEqNulls()
public void TestEqContains()
{
var tm = new TraitMethods("yo");
var list = new List<TraitMethods>();
list.Add(tm);
var list = new List<TraitMethods>
{
tm
};

Assert.Contains(tm, list);
Assert.Contains(new TraitMethods("yo"), list);
Expand Down Expand Up @@ -90,20 +89,17 @@ public void TestEq()
{
using (var methods = new ProcTraitMethods("yo"))
{
// Values are equal if input is the same
Assert.Equal(methods, new ProcTraitMethods("yo"));
Assert.True(methods == new ProcTraitMethods("yo"));

Assert.Equal(methods, methods);

Assert.NotEqual(methods, new ProcTraitMethods("yoyo"));
Assert.True(methods != new ProcTraitMethods("yoyo"));
}

Assert.False(new ProcTraitMethods("yo") == null);
// Values are not referentially equal
Assert.False(methods == new ProcTraitMethods("yo"));
}
}

[Fact]
public void TestEqNulls()
public void TestEqNull()
{
ProcTraitMethods? t1 = null;
ProcTraitMethods? t2 = null;
Expand All @@ -116,8 +112,10 @@ public void TestEqNulls()
public void TestEqContains()
{
var tm = new ProcTraitMethods("yo");
var list = new List<ProcTraitMethods>();
list.Add(tm);
var list = new List<ProcTraitMethods>
{
tm
};

Assert.Contains(tm, list);
Assert.Contains(new ProcTraitMethods("yo"), list);
Expand Down

0 comments on commit bd9186b

Please sign in to comment.