fix: make SemanticVersionRange equality structural
The type was a record struct whose ==/Equals/GetHashCode were synthesized from all fields, including the _sets array, so two ranges that parse to the same constraint sets compared as unequal (reference-sensitive on the array). This also broke using ranges as dictionary keys, where lookup relies on value equality. Change the type to a plain readonly struct implementing IEquatable<SemanticVersionRange> with structural equality over the constraint sets (operation + version per comparator). The custom ToString already existed, so no display behaviour is lost. Add a failing-then-passing test.
This commit is contained in:
parent
95eb4f05a2
commit
f9531fe112
6 changed files with 99 additions and 4 deletions
|
|
@ -282,4 +282,14 @@ internal sealed class SemanticVersionRangeTests
|
|||
await Assert.That(success).IsFalse();
|
||||
await Assert.That(charsWritten).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_treat_structurally_equal_ranges_as_equal()
|
||||
{
|
||||
var a = SemanticVersionRange.Parse("^1.2.3");
|
||||
var b = SemanticVersionRange.Parse("[1.2.3,2.0.0)");
|
||||
|
||||
await Assert.That(a == b).IsTrue();
|
||||
await Assert.That(a.GetHashCode()).IsEqualTo(b.GetHashCode());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue