Skip to content
This repository has been archived by the owner on Oct 10, 2021. It is now read-only.

Commit

Permalink
Add version bumping for SemVerFull
Browse files Browse the repository at this point in the history
  • Loading branch information
NthPortal committed Mar 8, 2017
1 parent 02ed4d2 commit 4cac385
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,9 @@ assert(Version(1)(2)(5).bumpMajor == Version(2)(0)(0))
assert((Version(1)(2)(5) -- Snapshot).bumpPatch == Version(1)(2)(6) -- Snapshot)
assert((Version(1)(2)(5) -- Snapshot).bumpMinor == Version(1)(3)(0) -- Snapshot)
assert((Version(1)(2)(5) -- Snapshot).bumpMajor == Version(2)(0)(0) -- Snapshot)

// SemVerFull bumping
assert((Version(1)(2)(5) -- Snapshot + "commit.48e5a2e").bumpPatch == Version(1)(2)(6) -- Snapshot + "commit.48e5a2e")
assert((Version(1)(2)(5) -- Snapshot + "commit.48e5a2e").bumpMinor == Version(1)(3)(0) -- Snapshot + "commit.48e5a2e")
assert((Version(1)(2)(5) -- Snapshot + "commit.48e5a2e").bumpMajor == Version(2)(0)(0) -- Snapshot + "commit.48e5a2e")
```
29 changes: 29 additions & 0 deletions src/main/scala/com/nthportal/versions/semver/SemVerFull.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.nthportal.versions
package semver

import semver._

/**
* A [[http://semver.org/spec/2.0.0.html SemVer 2.0.0]] version possibly
* containing build metadata.
Expand All @@ -12,6 +14,33 @@ package semver
*/
case class SemVerFull[E, M](extendedVersion: v3.ExtendedVersion[E], buildMetadata: Option[M])
extends Ordered[SemVerFull[E, _]] {
/**
* Returns a [[SemVerFull version]] with the major version number
* incremented by `1`, as described in
* [[http://semver.org/spec/v2.0.0.html#spec-item-8 the specification]].
*
* @return a version with the major version number incremented by `1`
*/
def bumpMajor: SemVerFull[E, M] = copy(extendedVersion = extendedVersion.bumpMajor)

/**
* Returns a [[SemVerFull version]] with the minor version number
* incremented by `1`, as described in
* [[http://semver.org/spec/v2.0.0.html#spec-item-7 the specification]].
*
* @return a version with the minor version number incremented by `1`
*/
def bumpMinor: SemVerFull[E, M] = copy(extendedVersion = extendedVersion.bumpMinor)

/**
* Returns a [[SemVerFull version]] with the patch version number
* incremented by `1`, as described in
* [[http://semver.org/spec/v2.0.0.html#spec-item-6 the specification]].
*
* @return a version with the patch version number incremented by `1`
*/
def bumpPatch: SemVerFull[E, M] = copy(extendedVersion = extendedVersion.bumpPatch)

override def compare(that: SemVerFull[E, _]): Int = this.extendedVersion compare that.extendedVersion

override def toString = extendedVersion.toString + {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class SemVerFullTest extends SimpleSpec {
v2 should not equal v1
}

it should "bump versions correctly" in {
val v1 = v3.Version(1)(1)(1) -- Snapshot + "build.12654"

v1.bumpMajor should be (v3.Version(2)(0)(0) -- Snapshot + "build.12654")
v1.bumpMinor should be (v3.Version(1)(2)(0) -- Snapshot + "build.12654")
v1.bumpPatch should be (v3.Version(1)(1)(2) -- Snapshot + "build.12654")
}

it should "compare correctly" in {
val v0 = v3.Version(1)(0)(0) -- Snapshot + "build.12654"
val v1 = v3.Version(1)(0)(0) -- Snapshot + 12654
Expand Down

0 comments on commit 4cac385

Please sign in to comment.