Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey, thanks for this library!
I noticed that loose requirements weren't evaluating as expected for NPM. It seems like this is because
null
minor/patch versions default to zero, but I believe the correct behavior is to stop comparison at any missing parts of the semver.For example,
"2.0.2" satisfies "=2"
is more like"2 satisfies "=2"
than"2.0.2" satisfies "=2.0.0"
, if that makes sense.I changed
isGreaterThan
andisEqualTo
when type isSemverType.NPM
so that it more closely matches the behavior in Node. I had to fix one erroneous test that asserted thatnew Semver("2.0.1", SemverType.NPM).satisfies(">2.0 <3.0")
should betrue
(it should ignore the patch version because the requirement isn't fully qualified). All the rest were fine. I added a couple more tests for good measure.Update:
I tried to add a few more test cases and noticed that they failed. After digging in a little, it looks like the implementation of
toReversePolishNotation
was a little off.Everything is supposed to get added to one side of the queue, but apparently some tokens were getting added to the other side instead, perhaps to make unary operators work. I think the trick for unary operators is not to add the two tokens to the front of the queue, but to add them in the back in reverse order.
I flipped
req1
andreq2
inevaluateReversePolishNotation
to keep the tests happy, but the way it evaluates is still equivalent (woo commutative property).I believe these changes address the unexpected behavior mentioned in #15 and #29