Skip to content

Commit

Permalink
Fix whith the EdiFragment IComparer implementation. When there is an…
Browse files Browse the repository at this point in the history
… index vs a range. closes #190
  • Loading branch information
cleftheris committed May 17, 2021
1 parent b3d44f0 commit 2b2d86e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/indice.Edi/EdiPathFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public override bool Equals(object obj) {
/// <param name="other">The object to check equality with</param>
/// <returns></returns>
public bool Equals(EdiPathFragment other) {
bool eq = IsWildcard || other.IsWildcard || (HasIndex && Index.Equals(other.Index)) || Value.Equals(other.Value);
bool eq = IsWildcard || other.IsWildcard || (HasIndex && other.HasIndex && Index.Equals(other.Index)) || Value.Equals(other.Value);

if (!eq && (IsRange || other.HasIndex)) {
return Min <= other.Index && Max >= other.Index;
Expand Down Expand Up @@ -185,6 +185,14 @@ public int CompareTo(object obj) {
return 0;
} else if (other.HasIndex && HasIndex) {
return Index.CompareTo(other.Index);
} else if (other.HasIndex && IsRange) {
return Max < other.Index ? -1 :
Min > other.Index ? 1 :
0;
} else if (other.IsRange && HasIndex) {
return Index < other.Min ? -1 :
Index > other.Max ? 1 :
0;
} else {
return string.Compare(Value, other.Value, StringComparison.OrdinalIgnoreCase);
}
Expand Down
1 change: 1 addition & 0 deletions src/indice.Edi/indice.Edi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Bug fix for Wildcard paths working only for collections #170.
- Fix for segment collection serialization. When some collection items where being serialized as elements instead #168.
- Fix missing path (non existing) on condition attirute should not enter infinite loop #188
- Fix whith the EdiFragment IComparer implementation. When there is an index vs a range. #190
</PackageReleaseNotes>
<PackageIcon>icon-256.png</PackageIcon>
<PackageProjectUrl>https://github.com/indice-co/EDI.Net</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion test/indice.Edi.Tests/SerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public void Serialize_RangeError_Issue190() {
Names = new List<EdiFact_Issue190.GivenName> {"Hello", "World"}
};
var badResult = Serialize(bad);
var badExpected = new StringBuilder().AppendLine("UNA:+.? '").AppendLine("TIF+ADT+Hello+World'").ToString();
var badExpected = new StringBuilder().AppendLine("UNA:+.? '").AppendLine("TIF+:ADT+Hello+World'").ToString();
Assert.Equal(badExpected, badResult);

string Serialize<T>(T data) {
Expand Down

0 comments on commit 2b2d86e

Please sign in to comment.