aboutsummaryrefslogtreecommitdiffstats
path: root/api/src/test/java/org/semver/VersionTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/test/java/org/semver/VersionTest.java')
-rwxr-xr-xapi/src/test/java/org/semver/VersionTest.java30
1 files changed, 28 insertions, 2 deletions
diff --git a/api/src/test/java/org/semver/VersionTest.java b/api/src/test/java/org/semver/VersionTest.java
index 76dd9a3..82d796e 100755
--- a/api/src/test/java/org/semver/VersionTest.java
+++ b/api/src/test/java/org/semver/VersionTest.java
@@ -16,6 +16,9 @@
*/
package org.semver;
+import java.util.ArrayList;
+import java.util.List;
+
import org.junit.Assert;
import org.junit.Test;
@@ -54,6 +57,8 @@ public class VersionTest {
Version.parse("1.2-RC-SNAPSHOT");
}
+
+
@Test(expected=IllegalArgumentException.class)
public void shouldInvalidVersion1NotBeParsed() {
Version.parse("invalid");
@@ -103,6 +108,27 @@ public class VersionTest {
Assert.assertTrue(Version.parse("1.0.0Beta").compareTo(Version.parse("1.0.0Alpha")) > 0);
Assert.assertFalse(Version.parse("0.0.0").compareTo(Version.parse("0.0.0")) > 0);
Assert.assertFalse(Version.parse("0.0.0").compareTo(Version.parse("0.0.1")) > 0);
+ // based on http://semver.org/
+ // Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
+ String[] versions = { "1.0.0-alpha", "1.0.0-alpha.1", "1.0.0-alpha.beta", "1.0.0-beta", "1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", "1.0.0" };
+ assertTotalOrder(versions);
+ }
+
+ private void assertTotalOrder(String[] versions) {
+ List<String> problems = new ArrayList<String>();
+ for (int i = 0; i < versions.length - 1; i++) {
+ Version v1 = Version.parse(versions[i]);
+ for (int j = (i + 1); j < versions.length; j++) {
+ Version v2 = Version.parse(versions[j]);
+ int compare = v1.compareTo(v2);
+ if (compare >= 0 ) {
+ problems.add(v1 + ( compare == 0 ? " = " : " > ") + v2);
+ }
+ }
+ }
+ if (problems.size() > 0) {
+ Assert.fail("incorrect comparisons: " + problems);
+ }
}
@Test
@@ -125,6 +151,6 @@ public class VersionTest {
final Version version = new Version(major, minor, patch);
version.next(null);
- }
-
+ }
+
}