Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/haxelib/SemVer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ abstract SemVer(String) to String {
return isValid(this);

@:op(a > b) static inline function gt(a:SemVer, b:SemVer)
return compare(a, b) == 1;
return compare(a, b) > 0;

@:op(a >= b) static inline function gteq(a:SemVer, b:SemVer)
return compare(a, b) != -1;
return compare(a, b) >= 0;

@:op(a < b) static inline function lt(a:SemVer, b:SemVer)
return compare(a, b) == -1;
return compare(a, b) < 0;

@:op(a <= b) static inline function lteq(a:SemVer, b:SemVer)
return compare(a, b) != 1;
return compare(a, b) <= 0;

@:op(a == b) static inline function eq(a:SemVer, b:SemVer)
return compare(a, b) == 0;
Expand Down
11 changes: 11 additions & 0 deletions test/tests/TestSemVer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ class TestSemVer extends TestBase {
assertEquals( "invalid", parseInvalid("10.50.2-rc.01"));
}

public function testPreviewComparison() {
assertTrue(SemVer.ofString("0.1.1-beta.1") < SemVer.ofString("0.1.1"));
assertTrue(SemVer.ofString("0.1.1-beta.1") > SemVer.ofString("0.1.0"));
assertTrue(SemVer.ofString("0.1.1-alpha.2") > SemVer.ofString("0.1.1-alpha.1"));
assertTrue(SemVer.ofString("0.1.1-beta.1") > SemVer.ofString("0.1.1-alpha.2"));
assertTrue(SemVer.ofString("0.1.1-rc.1") > SemVer.ofString("0.1.1-beta.1"));
#if !(server || haxelib_api)
assertTrue(SemVer.ofString("0.1.1-preview.1") > SemVer.ofString("0.1.1-rc.1"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the bug was specific to preview versions, on hashlink this was evaluating to false:

SemVer.ofString("1.2.2") < SemVer.ofString("1.2.4")

because the comparison returned -2

#end
}

function parseInvalid( str:String ):String {
return try {
SemVer.ofString(str);
Expand Down
Loading