Skip to content

Commit

Permalink
1.8.4: version values now uint
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Nov 3, 2019
1 parent 630e53c commit 28e402a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions bump.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ from macros import nil

type
Version* = tuple
major: int
minor: int
patch: int
major: uint
minor: uint
patch: uint

Target* = tuple
repo: string
Expand Down Expand Up @@ -173,20 +173,20 @@ proc parseVersion*(nimble: string): Option[Version] =
if dotted.len != 3:
continue
try:
result = (major: dotted[0].parseInt,
minor: dotted[1].parseInt,
patch: dotted[2].parseInt).some
result = (major: dotted[0].parseUInt,
minor: dotted[1].parseUInt,
patch: dotted[2].parseUInt).some
except ValueError:
discard

proc bumpVersion*(ver: Version; major, minor, patch = false): Option[Version] =
## increment the version by the specified metric
if major:
result = (ver.major + 1, 0, 0).some
result = (ver.major + 1'u, 0'u, 0'u).some
elif minor:
result = (ver.major, ver.minor + 1, 0).some
result = (ver.major, ver.minor + 1'u, 0'u).some
elif patch:
result = (ver.major, ver.minor, ver.patch + 1).some
result = (ver.major, ver.minor, ver.patch + 1'u).some

proc withCrazySpaces*(version: Version; line = ""): string =
## insert a new version into a line which may have "crazy spaces"
Expand Down
2 changes: 1 addition & 1 deletion bump.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "1.8.3"
version = "1.8.4"
author = "disruptek"
description = "a tiny tool to bump nimble versions"
license = "MIT"
Expand Down
22 changes: 11 additions & 11 deletions tests/tbump.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import bump
suite "bump":
setup:
let
ver123 {.used.} = (major: 1, minor: 2, patch: 3)
ver155 {.used.} = (major: 1, minor: 5, patch: 5)
ver170 {.used.} = (major: 1, minor: 7, patch: 0)
ver171 {.used.} = (major: 1, minor: 7, patch: 1)
ver456 {.used.} = (major: 4, minor: 5, patch: 6)
ver457 {.used.} = (major: 4, minor: 5, patch: 7)
ver789 {.used.} = (major: 7, minor: 8, patch: 9)
ver799 {.used.} = (major: 7, minor: 9, patch: 9)
ver123 {.used.} = (major: 1'u, minor: 2'u, patch: 3'u)
ver155 {.used.} = (major: 1'u, minor: 5'u, patch: 5'u)
ver170 {.used.} = (major: 1'u, minor: 7'u, patch: 0'u)
ver171 {.used.} = (major: 1'u, minor: 7'u, patch: 1'u)
ver456 {.used.} = (major: 4'u, minor: 5'u, patch: 6'u)
ver457 {.used.} = (major: 4'u, minor: 5'u, patch: 7'u)
ver789 {.used.} = (major: 7'u, minor: 8'u, patch: 9'u)
ver799 {.used.} = (major: 7'u, minor: 9'u, patch: 9'u)
aList {.used.} = ""
bList {.used.} = """
v.1.2.3
Expand Down Expand Up @@ -87,10 +87,10 @@ suite "bump":
check tagv155.get == "V1.5.5"

test "version validity checks out":
check (0, 0, 0).isValid == false
check (0, 0, 1).isValid == true
check (0'u, 0'u, 0'u).isValid == false
check (0'u, 0'u, 1'u).isValid == true

test "strange use-supplied versions do not parse":
test "strange user-supplied versions do not parse":
check parseVersion("""version = "-1.2.3"""").isNone
check parseVersion("""version = "12.3"""").isNone
check parseVersion("""version = "123"""").isNone
Expand Down

0 comments on commit 28e402a

Please sign in to comment.