Skip to content
Browse files

small fixes in the way the prereleases are specified and parsed

  • Loading branch information...
1 parent 84fc954 commit 043c181c8984fbe60d2ae0de8d861bb6de805999 @kikito committed Jan 15, 2012
Showing with 16 additions and 11 deletions.
  1. +11 −9 semver.lua
  2. +5 −2 spec/semver_spec.lua
View
20 semver.lua
@@ -16,10 +16,12 @@ local function present(value)
return value and value ~= ''
end
-local function filterPrerelease(prerelease)
- local identifiers = prerelease:match("-([%w-][%.%w-]+)")
- assert(identifiers, ("The prerelease %q must start with a dash and be followed by dashes, alphanumerics or dots."):format(prerelease))
- return identifiers
+local function parsePrerelease(extra)
+ if not present(extra) then return end
+
+ local prerelease = extra:match("-([%w-][%.%w-]+)")
+ assert(prerelease, ("The prerelease %q must start with a dash and be followed by dashes, alphanumerics or dots."):format(extra))
+ return prerelease
end
local methods = {}
@@ -58,16 +60,14 @@ end
-- defined as local at the begining of the file
-version = function(major, minor, patch, prerelease)
+version = function(major, minor, patch, extra)
assert(major, "At least one parameter is needed")
if type(major) == 'string' then
- local sMajor, sMinor, sPatch, sPrerelease = major:match("^(%d+)%.?(%d*)%.?(%d*)(.-)$")
+ local sMajor, sMinor, sPatch
+ sMajor, sMinor, sPatch, extra = major:match("^(%d+)%.?(%d*)%.?(%d*)(.-)$")
assert(type(sMajor) == 'string', ("Could not extract version number(s) from %q"):format(major))
major, minor, patch = tonumber(sMajor), tonumber(sMinor), tonumber(sPatch)
- if present(sPrerelease) then
- prerelease = filterPrerelease(sPrerelease)
- end
end
patch = patch or 0
@@ -77,6 +77,8 @@ version = function(major, minor, patch, prerelease)
checkPositiveInteger(minor, "minor")
checkPositiveInteger(patch, "patch")
+ local prerelease = parsePrerelease(extra)
+
local result = {major=major, minor=minor, patch=patch, prerelease=prerelease}
return setmetatable(result, mt)
end
View
7 spec/semver_spec.lua
@@ -25,7 +25,7 @@ context('semver', function()
end)
it('parses prereleases, if they exist', function()
- checkVersion(v(1,2,3,"alpha"), 1,2,3,"alpha")
+ checkVersion(v(1,2,3,"-alpha"), 1,2,3,"alpha")
end)
end)
@@ -82,7 +82,7 @@ context('semver', function()
end)
it("works with a prerelease", function()
- assert_equal("1.2.3-beta", tostring(v(1,2,3,'beta')))
+ assert_equal("1.2.3-beta", tostring(v(1,2,3,'-beta')))
end)
end)
@@ -117,6 +117,9 @@ context('semver', function()
test("false if major =, minor =, but patch >", function()
assert_greater_than(v'0.0.2', v'0.0.1')
end)
+ describe("prereleases", function()
+
+ end)
end)
describe("nextPatch", function()

0 comments on commit 043c181

Please sign in to comment.
Something went wrong with that request. Please try again.