Skip to content

Commit

Permalink
Merge pull request #19 from InfiniteEnergy/prefix-match-bugs
Browse files Browse the repository at this point in the history
bugfix *StartsWith* matchers
  • Loading branch information
ryepup committed Apr 23, 2021
2 parents d9e7184 + df615eb commit 4bed2a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/XlsxCompare.Tests/MatchByTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public class MatchByTests
[DataRow(MatchBy.Date, "2021-04-01", "04/01/2021")]
[DataRow(MatchBy.Date, "2021-04-01 4:00AM", "04/01/2021")]
[DataRow(MatchBy.StringLeftStartsWithRight, "asdf", "as")]
[DataRow(MatchBy.StringLeftStartsWithRight, "", "")]
[DataRow(MatchBy.Decimal, "0.084400", "0.0844")]
[DataRow(MatchBy.Decimal, "0.00", "0")]
[DataRow(MatchBy.StringRightStartsWithLeft, "asdf", "asdf and then some")]
[DataRow(MatchBy.StringRightStartsWithLeft, "", "")]
public void IsMatch_ThingsThatMatch_ReturnsTrue(MatchBy? match, string left, string right)
{
Assert.IsTrue(match.IsMatch(left, right));
Expand Down
8 changes: 6 additions & 2 deletions src/XlsxCompare/MatchBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ private static bool IsDateMatch(string left, string right)
&& leftDate.Date == rightDate.Date);

private static bool IsLeftStartsWithRightMatch(string left, string right)
=> right.Length > 0
&& left.StartsWith(right, StringComparison.OrdinalIgnoreCase);
=> (left, right) switch
{
("", "") => true, // both empty is a match
(_, "") => false, // left starting with empty doesn't count
(_, _) => left.StartsWith(right, StringComparison.OrdinalIgnoreCase),
};

private static bool IsDecimalMatch(string left, string right)
=> IsStringMatch(left, right)
Expand Down

0 comments on commit 4bed2a7

Please sign in to comment.