Skip to content

Commit

Permalink
Renamed: SemanticVersion => SemVer
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-lee committed Apr 15, 2019
1 parent ef2d130 commit d112abd
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 161 deletions.
36 changes: 18 additions & 18 deletions src/main/scala/kevinlee/semver/versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ trait SequenceBasedVersion[T] extends Ordered[T] {
def render: String
}

final case class SemanticVersion(
final case class SemVer(
major: Major
, minor: Minor
, patch: Patch
, pre: Option[PreRelease]
, buildMetadata: Option[BuildMetaInfo]
) extends SequenceBasedVersion[SemanticVersion] {
) extends SequenceBasedVersion[SemVer] {

override def compare(that: SemanticVersion): Int = {
override def compare(that: SemVer): Int = {
val mj = this.major.major.compareTo(that.major.major)
if (mj === 0) {
val mn = this.minor.minor.compareTo(that.minor.minor)
Expand Down Expand Up @@ -260,24 +260,24 @@ final case class SemanticVersion(
}).toString
}

object SemanticVersion {
object SemVer {
val major0: Major = Major(0)
val minor0: Minor = Minor(0)
val patch0: Patch = Patch(0)

val semanticVersionRegex: Regex =
val semVerRegex: Regex =
"""(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z\d-\.]+)?)?(?:\+([a-zA-Z\d-\.]+)?)?""".r

def parseUnsafe(version: String): SemanticVersion =
def parseUnsafe(version: String): SemVer =
parse(version) match {
case Right(semVer) =>
semVer
case Left(error) =>
sys.error(ParseError.render(error))
}

def parse(version: String): Either[ParseError, SemanticVersion] = version match {
case semanticVersionRegex(major, minor, patch, pre, meta) =>
def parse(version: String): Either[ParseError, SemVer] = version match {
case semVerRegex(major, minor, patch, pre, meta) =>
val preRelease = AdditionalInfo.parsePreRelease(pre)
val metaInfo = AdditionalInfo.parseBuildMetaInfo(meta)
(preRelease, metaInfo) match {
Expand All @@ -289,7 +289,7 @@ object SemanticVersion {
Left(ParseError.buildMetadataParseError(metaError))
case (Right(preR), Right(metaI)) =>
Right(
SemanticVersion(
SemVer(
Major(major.toInt), Minor(minor.toInt), Patch(patch.toInt),
preR, metaI
)
Expand All @@ -300,17 +300,17 @@ object SemanticVersion {
Left(ParseError.invalidVersionStringError(version))
}

def noIdentifier(major: Major, minor: Minor, patch: Patch): SemanticVersion =
SemanticVersion(major, minor, patch, None, None)
def noIdentifier(major: Major, minor: Minor, patch: Patch): SemVer =
SemVer(major, minor, patch, None, None)

def withMajor(major: Major): SemanticVersion =
SemanticVersion(major, minor0, patch0, None, None)
def withMajor(major: Major): SemVer =
SemVer(major, minor0, patch0, None, None)

def withMinor(minor: Minor): SemanticVersion =
SemanticVersion(major0, minor, patch0, None, None)
def withMinor(minor: Minor): SemVer =
SemVer(major0, minor, patch0, None, None)

def withPatch(patch: Patch): SemanticVersion =
SemanticVersion(major0, minor0, patch, None, None)
def withPatch(patch: Patch): SemVer =
SemVer(major0, minor0, patch, None, None)
}

sealed trait ParseError
Expand Down Expand Up @@ -353,7 +353,7 @@ object ParseError {
|""".stripMargin

case InvalidVersionStringError(value) =>
s"Invalid SemanticVersion String. value: $value"
s"Invalid SemVer String. value: $value"
}

def invalidAlphaNumHyphenError(c: Char, rest: List[Char]): ParseError =
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/kevinlee/semver/Gens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ object Gens {
genMinMaxIdentifier(genMinMaxAlphaNumHyphenGroup)
.map { case (min, max) => (BuildMetaInfo(min), BuildMetaInfo(max)) }

def genSemanticVersion: Gen[SemanticVersion] = for {
def genSemVer: Gen[SemVer] = for {
major <- genMajor
minor <- genMinor
patch <- genPatch
pre <- genPreRelease.option
meta <- genBuildMetaInfo.option
} yield SemanticVersion(major, minor, patch, pre, meta)
} yield SemVer(major, minor, patch, pre, meta)

def genMinMaxSemanticVersions: Gen[(SemanticVersion, SemanticVersion)] = for {
def genMinMaxSemVers: Gen[(SemVer, SemVer)] = for {
majorPair <- genMinMaxMajors
minorPair <- genMinMaxMinors
patchPair <- genMinMaxPatches
Expand All @@ -252,14 +252,14 @@ object Gens {
xy => (Option(xy._1), Option(xy._2))
)

(SemanticVersion(
(SemVer(
majorPair._1
, minorPair._1
, patchPair._1
, pre1
, meta1
),
SemanticVersion(
SemVer(
majorPair._2
, minorPair._2
, patchPair._2
Expand Down
Loading

0 comments on commit d112abd

Please sign in to comment.