Skip to content

Commit

Permalink
Fix IsInRange and added unit tests. (AvaloniaUI#15079)
Browse files Browse the repository at this point in the history
  • Loading branch information
appel1 authored Mar 23, 2024
1 parent bad2e8d commit da6b11e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Avalonia.Base/Media/UnicodeRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public UnicodeRangeSegment(int start, int end)
/// </returns>
public bool IsInRange(int value)
{
return value - Start <= End - Start;
return Start <= value && value <= End;
}

/// <summary>
Expand Down
23 changes: 23 additions & 0 deletions tests/Avalonia.Base.UnitTests/Media/UnicodeRangeSegmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,28 @@ public void Should_Parse(string s, int expectedStart, int expectedEnd)

Assert.Equal(expectedEnd, segment.End);
}

[InlineData(0)]
[InlineData(19)]
[InlineData(26)]
[InlineData(100)]
[Theory]
public void InRange_Should_Return_False_For_Values_Outside_Range(int value)
{
var segment = new UnicodeRangeSegment(20, 25);

Assert.Equal(false, segment.IsInRange(value));
}

[InlineData(20)]
[InlineData(21)]
[InlineData(22)]
[Theory]
public void InRange_Should_Return_True_For_Values_Within_Range(int value)
{
var segment = new UnicodeRangeSegment(20, 22);

Assert.Equal(true, segment.IsInRange(value));
}
}
}

0 comments on commit da6b11e

Please sign in to comment.