aboutsummaryrefslogtreecommitdiffstats
path: root/api/src
diff options
context:
space:
mode:
Diffstat (limited to 'api/src')
-rwxr-xr-xapi/src/main/java/org/semver/Version.java18
-rwxr-xr-xapi/src/test/java/org/semver/VersionTest.java19
2 files changed, 34 insertions, 3 deletions
diff --git a/api/src/main/java/org/semver/Version.java b/api/src/main/java/org/semver/Version.java
index 8b14d3c..09046b8 100755
--- a/api/src/main/java/org/semver/Version.java
+++ b/api/src/main/java/org/semver/Version.java
@@ -125,11 +125,23 @@ public final class Version implements Comparable<Version> {
switch (element) {
case MAJOR:
- return new Version(this.major+1, 0, 0);
+ if (special == null || this.minor != 0 || this.patch != 0) {
+ return new Version(this.major + 1, 0, 0);
+ } else {
+ return new Version(this.major, 0, 0);
+ }
case MINOR:
- return new Version(this.major, this.minor+1, 0);
+ if (special == null || this.patch != 0) {
+ return new Version(this.major, this.minor + 1, 0);
+ } else {
+ return new Version(this.major, this.minor, 0);
+ }
case PATCH:
- return new Version(this.major, this.minor, this.patch+1);
+ if (special == null) {
+ return new Version(this.major, this.minor, this.patch + 1);
+ } else {
+ return new Version(this.major, this.minor, this.patch);
+ }
default:
throw new IllegalArgumentException("Unknown element <"+element+">");
}
diff --git a/api/src/test/java/org/semver/VersionTest.java b/api/src/test/java/org/semver/VersionTest.java
index 82d796e..bdefa5a 100755
--- a/api/src/test/java/org/semver/VersionTest.java
+++ b/api/src/test/java/org/semver/VersionTest.java
@@ -143,6 +143,25 @@ public class VersionTest {
Assert.assertEquals(version.next(Version.Element.PATCH), new Version(major, minor, patch+1));
}
+ @Test
+ public void nextFromPre() {
+ final Version version1 = new Version(1, 0, 0, "-", "rc1");
+ Assert.assertEquals(new Version(1, 0, 0), version1.next(Version.Element.MAJOR));
+ Assert.assertEquals(new Version(1, 0, 0), version1.next(Version.Element.MINOR));
+ Assert.assertEquals(new Version(1, 0, 0), version1.next(Version.Element.PATCH));
+
+ final Version version2 = new Version(1, 1, 0, "-", "rc1");
+ Assert.assertEquals(new Version(2, 0, 0), version2.next(Version.Element.MAJOR));
+ Assert.assertEquals(new Version(1, 1, 0), version2.next(Version.Element.MINOR));
+ Assert.assertEquals(new Version(1, 1, 0), version2.next(Version.Element.PATCH));
+
+ final Version version3 = new Version(1, 1, 1, "-", "rc1");
+ Assert.assertEquals(new Version(2, 0, 0), version3.next(Version.Element.MAJOR));
+ Assert.assertEquals(new Version(1, 2, 0), version3.next(Version.Element.MINOR));
+ Assert.assertEquals(new Version(1, 1, 1), version3.next(Version.Element.PATCH));
+ }
+
+
@Test(expected=IllegalArgumentException.class)
public void shouldNextWithNullComparisonTypeFail() {
final int major = 1;