[jsemver] 27/95: Adapt to SemVer 2.0.0-rc.2
Alexandre Viau
reazem-guest at moszumanska.debian.org
Mon Feb 16 14:58:27 UTC 2015
This is an automated email from the git hooks/post-receive script.
reazem-guest pushed a commit to branch master
in repository jsemver.
commit 5c39ab15d86351170ec00babcae889e2c4e7bc2b
Author: Zafar Khaja <zafarkhaja at gmail.com>
Date: Sat Mar 30 20:34:47 2013 +0400
Adapt to SemVer 2.0.0-rc.2
---
.../java/com/github/zafarkhaja/semver/Version.java | 58 +++++++++++-------
.../com/github/zafarkhaja/semver/VersionTest.java | 71 ++++++++++++++++------
2 files changed, 86 insertions(+), 43 deletions(-)
diff --git a/src/main/java/com/github/zafarkhaja/semver/Version.java b/src/main/java/com/github/zafarkhaja/semver/Version.java
index 372a785..8859cb1 100644
--- a/src/main/java/com/github/zafarkhaja/semver/Version.java
+++ b/src/main/java/com/github/zafarkhaja/semver/Version.java
@@ -53,10 +53,18 @@ public class Version implements Comparable<Version> {
.append(MetadataVersion.FORMAT)
.append(")?")
.append("$");
-
+
SEMVER_PATTERN = Pattern.compile(sb.toString());
}
+ Version(NormalVersion normal) {
+ this(normal, null, null);
+ }
+
+ Version(NormalVersion normal, MetadataVersion preRelease) {
+ this(normal, preRelease, null);
+ }
+
Version(
NormalVersion normal,
MetadataVersion preRelease,
@@ -93,15 +101,36 @@ public class Version implements Comparable<Version> {
}
public Version incrementMajorVersion() {
- return new Version(normal.incrementMajor(), preRelease, build);
+ return new Version(normal.incrementMajor());
+ }
+
+ public Version incrementMajorVersion(String preRelease) {
+ return new Version(
+ normal.incrementMajor(),
+ new MetadataVersion(preRelease)
+ );
}
public Version incrementMinorVersion() {
- return new Version(normal.incrementMinor(), preRelease, build);
+ return new Version(normal.incrementMinor());
+ }
+
+ public Version incrementMinorVersion(String preRelease) {
+ return new Version(
+ normal.incrementMinor(),
+ new MetadataVersion(preRelease)
+ );
}
public Version incrementPatchVersion() {
- return new Version(normal.incrementPatch(), preRelease, build);
+ return new Version(normal.incrementPatch());
+ }
+
+ public Version incrementPatchVersion(String preRelease) {
+ return new Version(
+ normal.incrementPatch(),
+ new MetadataVersion(preRelease)
+ );
}
public int getMajorVersion() {
@@ -124,7 +153,7 @@ public class Version implements Comparable<Version> {
return (preRelease != null) ? preRelease.toString() : "";
}
- public String getBuildVersion() {
+ public String getBuildMetadata() {
return (build != null) ? build.toString() : "";
}
@@ -171,7 +200,7 @@ public class Version implements Comparable<Version> {
sb.append(PRE_RELEASE_PREFIX).append(getPreReleaseVersion());
}
if (build != null) {
- sb.append(BUILD_PREFIX).append(getBuildVersion());
+ sb.append(BUILD_PREFIX).append(getBuildMetadata());
}
return sb.toString();
}
@@ -181,9 +210,6 @@ public class Version implements Comparable<Version> {
int result = normal.compareTo(other.normal);
if (result == 0) {
result = comparePreReleases(other);
- if (result == 0) {
- result = compareBuilds(other);
- }
}
return result;
}
@@ -201,18 +227,4 @@ public class Version implements Comparable<Version> {
}
return result;
}
-
- private int compareBuilds(Version other) {
- int result = 0;
- if (build != null && other.build != null) {
- result = build.compareTo(other.build);
- } else if (build == null ^ other.build == null) {
- /**
- * Build versions satisfy and have a higher precedence
- * than the associated normal version. (SemVer p.10)
- */
- result = (build == null) ? -1 : 1;
- }
- return result;
- }
}
diff --git a/src/test/java/com/github/zafarkhaja/semver/VersionTest.java b/src/test/java/com/github/zafarkhaja/semver/VersionTest.java
index d8fe02a..b13d7e7 100644
--- a/src/test/java/com/github/zafarkhaja/semver/VersionTest.java
+++ b/src/test/java/com/github/zafarkhaja/semver/VersionTest.java
@@ -54,22 +54,17 @@ public class VersionTest {
@Test
public void mayHaveBuildFollowingPatchOrPreReleaseAppendedWithPlus() {
Version v = Version.valueOf("1.2.3+build");
- assertEquals("build", v.getBuildVersion());
+ assertEquals("build", v.getBuildMetadata());
}
@Test
- public void shouldCompareBuildIfNormalAndPreReleaseAreEqual() {
- Version v1 = Version.valueOf("1.3.7-beta+build.1");
- Version v2 = Version.valueOf("1.3.7-beta+build.2");
- assertTrue(0 > v1.compareTo(v2));
- }
-
- @Test
- public void buildShouldHaveHigherPrecedenceThanAssociatedNormal() {
- Version v1 = Version.valueOf("1.3.7");
- Version v2 = Version.valueOf("1.3.7+build");
- assertTrue(0 > v1.compareTo(v2));
- assertTrue(0 < v2.compareTo(v1));
+ public void shouldIgnoreBuildMetadataWhenDeterminingVersionPrecedence() {
+ Version v1 = Version.valueOf("1.3.7-beta");
+ Version v2 = Version.valueOf("1.3.7-beta+build.1");
+ Version v3 = Version.valueOf("1.3.7-beta+build.2");
+ assertTrue(0 == v1.compareTo(v2));
+ assertTrue(0 == v1.compareTo(v3));
+ assertTrue(0 == v2.compareTo(v3));
}
@Test
@@ -126,12 +121,7 @@ public class VersionTest {
"1.0.0-beta.2",
"1.0.0-beta.11",
"1.0.0-rc.1",
- "1.0.0-rc.1+build.1",
"1.0.0",
- "1.0.0+0.3.7",
- "1.3.7+build",
- "1.3.7+build.2.b8f12d7",
- "1.3.7+build.11.e0f985a"
};
for (int i = 1; i < versions.length; i++) {
Version v1 = Version.valueOf(versions[i-1]);
@@ -148,7 +138,7 @@ public class VersionTest {
assertEquals(0, v.getPatchVersion());
assertEquals("1.0.0", v.getNormalVersion());
assertEquals("rc.1", v.getPreReleaseVersion());
- assertEquals("build.1", v.getBuildVersion());
+ assertEquals("build.1", v.getBuildMetadata());
}
@Test
@@ -159,6 +149,13 @@ public class VersionTest {
}
@Test
+ public void shouldIncrementMajorVersionWithPreReleaseIfProvided() {
+ Version v = Version.valueOf("1.2.3");
+ Version incrementedMajor = v.incrementMajorVersion("beta");
+ assertEquals("2.0.0-beta", incrementedMajor.toString());
+ }
+
+ @Test
public void shouldProvideIncrementMinorVersionMethod() {
Version v = Version.valueOf("1.2.3");
Version incrementedMinor = v.incrementMinorVersion();
@@ -166,12 +163,46 @@ public class VersionTest {
}
@Test
+ public void shouldIncrementMinorVersionWithPreReleaseIfProvided() {
+ Version v = Version.valueOf("1.2.3");
+ Version incrementedMinor = v.incrementMinorVersion("alpha");
+ assertEquals("1.3.0-alpha", incrementedMinor.toString());
+ }
+
+ @Test
public void shouldProvideIncrementPatchVersionMethod() {
Version v = Version.valueOf("1.2.3");
Version incrementedPatch = v.incrementPatchVersion();
assertEquals("1.2.4", incrementedPatch.toString());
}
-
+
+ @Test
+ public void shouldIncrementPatchVersionWithPreReleaseIfProvided() {
+ Version v = Version.valueOf("1.2.3");
+ Version incrementedPatch = v.incrementPatchVersion("rc");
+ assertEquals("1.2.4-rc", incrementedPatch.toString());
+ }
+
+ @Test
+ public void shouldDropBuildMetadataWhenIncrementing() {
+ Version v = Version.valueOf("1.2.3-alpha+build");
+
+ Version major1 = v.incrementMajorVersion();
+ assertEquals("2.0.0", major1.toString());
+ Version major2 = v.incrementMajorVersion("beta");
+ assertEquals("2.0.0-beta", major2.toString());
+
+ Version minor1 = v.incrementMinorVersion();
+ assertEquals("1.3.0", minor1.toString());
+ Version minor2 = v.incrementMinorVersion("beta");
+ assertEquals("1.3.0-beta", minor2.toString());
+
+ Version patch1 = v.incrementPatchVersion();
+ assertEquals("1.2.4", patch1.toString());
+ Version patch2 = v.incrementPatchVersion("beta");
+ assertEquals("1.2.4-beta", patch2.toString());
+ }
+
@Test
public void shouldBeImmutable() {
Version version = Version.valueOf("1.2.3");
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jsemver.git
More information about the pkg-java-commits
mailing list