zafarkhaja / jsemver

Java implementation of the SemVer Specification
MIT License
429 stars 82 forks source link

Alpha/Beta version compare #30

Closed eugene-nikolaev closed 7 years ago

eugene-nikolaev commented 7 years ago

Hello! It seems the version comparison is diverted with the SemVer Specification

       @Test
        public void preReleaseShouldHaveLowerPrecedenceThanAssociatedNormal() {
            Version v1 = Version.valueOf("1.3.7");
            Version v2 = Version.valueOf("1.3.7-alpha");
            assertTrue(0 < v1.compareTo(v2));
            assertTrue(0 > v2.compareTo(v1));
        }

So 1.3.7 < 1.3.7-alpha.

But according to the SemVer spec:

http://semver.org/


When major, minor, and patch are equal,
a pre-release version has lower precedence than a normal version.
Example: 1.0.0-alpha < 1.0.0.

It should be visa versa.

zafarkhaja commented 7 years ago

Hi, thank you for taking the time to contribute.

As far as I'm concerned every thing is correct here. According to the documentation compareTo returns

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

So

v1 > v2 => 0 < v1.compareTo(v2) // positive
v2 < v1 => 0 > v2.compareTo(v1) // negative

Let me know if you need any more clarifications.

eugene-nikolaev commented 7 years ago

Oh, I am sorry, I was confused somewhere in my tests using your awesome library. Thanks!