Skip to content

Commit

Permalink
Fix Graphics Font comparison method (#15985)
Browse files Browse the repository at this point in the history
* Fix the issue

* Added more tests

* Updated Impl
  • Loading branch information
jsuarezruiz authored Aug 8, 2023
1 parent 9ceea53 commit 7667bb8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Graphics/src/Graphics/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ public Font(string name, int weight = FontWeights.Normal, FontStyleType styleTyp
public FontStyleType StyleType { get; private set; }

public bool Equals(IFont other)
=> StyleType == other.StyleType && Weight == other.Weight && Name.Equals(other.Name, StringComparison.Ordinal);

=>
StyleType == other.StyleType &&
Weight == other.Weight &&
((Name is null && other.Name is null) || Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase));

public override bool Equals(object obj)
=> obj is IFont font && Equals(font);

Expand Down
33 changes: 33 additions & 0 deletions src/Graphics/tests/Graphics.Tests/FontUnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Xunit;

namespace Microsoft.Maui.Graphics.Tests
{
public class FontUnitTests
{
[Fact]
public void TestEqualsDefault()
{
Assert.True(Font.Default.Equals(Font.Default));
}

[Fact]
public void TestEqualsDefaultBold()
{
Assert.True(Font.DefaultBold.Equals(Font.DefaultBold));
}

[Fact]
public void TestEqualsDefaultFonts()
{
Assert.False(Font.Default.Equals(Font.DefaultBold));
}

[Fact]
public void TestEqualsArialFont()
{
var font1 = new Font("Arial");
var font2 = new Font("Arial");
Assert.True(font1.Equals(font2));
}
}
}

0 comments on commit 7667bb8

Please sign in to comment.