aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorJulien Eluard <[email protected]>2012-02-02 12:32:37 -0300
committerJulien Eluard <[email protected]>2012-02-02 12:32:37 -0300
commitcc75ee2c28e0c12db102cb63fd1b6fb2232cd280 (patch)
tree8a83d1542ef423f879537f04ffa7e953320ece58 /api
parent223a23e317278739cd45aacc04bd82ee7c70189e (diff)
Fixed incorrect multi-digit version parsing.
Diffstat (limited to 'api')
-rwxr-xr-xapi/src/main/java/org/semver/Version.java5
-rwxr-xr-xapi/src/test/java/org/semver/VersionTest.java15
2 files changed, 18 insertions, 2 deletions
diff --git a/api/src/main/java/org/semver/Version.java b/api/src/main/java/org/semver/Version.java
index a6871b5..b4c76ee 100755
--- a/api/src/main/java/org/semver/Version.java
+++ b/api/src/main/java/org/semver/Version.java
@@ -24,6 +24,7 @@ import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
+import org.apache.commons.lang.StringUtils;
/**
*
@@ -40,7 +41,7 @@ public final class Version implements Comparable<Version> {
MAJOR, MINOR, PATCH, SPECIAL;
}
- private static final String FORMAT = "(\\d)+\\.(\\d)+(?:\\.)?(\\d)*(?:\\.|-)?([A-Za-z][0-9A-Za-z-]*)?";
+ private static final String FORMAT = "(\\d+)\\.(\\d+)(?:\\.)?(\\d*)(?:\\.|-)?([A-Za-z][0-9A-Za-z-]*)?";
private static final Pattern PATTERN = Pattern.compile(Version.FORMAT);
private static final String SNAPSHOT_VERSION_SUFFIX = "-SNAPSHOT";
@@ -88,7 +89,7 @@ public final class Version implements Comparable<Version> {
final int minor = Integer.valueOf(matcher.group(2));
final int patch;
final String patchMatch = matcher.group(3);
- if (patchMatch != null) {
+ if (StringUtils.isNotEmpty(patchMatch)) {
patch = Integer.valueOf(patchMatch);
} else {
patch = 0;
diff --git a/api/src/test/java/org/semver/VersionTest.java b/api/src/test/java/org/semver/VersionTest.java
index 9ba6e2d..a7aa0e4 100755
--- a/api/src/test/java/org/semver/VersionTest.java
+++ b/api/src/test/java/org/semver/VersionTest.java
@@ -72,6 +72,21 @@ public class VersionTest {
}
@Test
+ public void shouldMajorBeCorrectlyIncremented() {
+ Assert.assertEquals(Version.parse("10.0.0"), Version.parse("9.0.0").next(Version.Element.MAJOR));
+ }
+
+ @Test
+ public void shouldMinorBeCorrectlyIncremented() {
+ Assert.assertEquals(Version.parse("0.10.0"), Version.parse("0.9.0").next(Version.Element.MINOR));
+ }
+
+ @Test
+ public void shouldPatchBeCorrectlyIncremented() {
+ Assert.assertEquals(Version.parse("0.0.10"), Version.parse("0.0.9").next(Version.Element.PATCH));
+ }
+
+ @Test
public void shouldDevelopmentBeInDevelopment() {
Assert.assertTrue(Version.parse("0.1.1").isInDevelopment());
Assert.assertFalse(Version.parse("1.1.1").isInDevelopment());