diff --git a/rockspecs/semver-1.2.1-1.rockspec b/rockspecs/semver-1.2.1-1.rockspec new file mode 100644 index 0000000..36ddfac --- /dev/null +++ b/rockspecs/semver-1.2.1-1.rockspec @@ -0,0 +1,25 @@ +package = "semver" +version = "1.2.1-1" +source = { + url = "git://github.com/kikito/semver.lua.git", +} +description = { + summary = "An implementation of semantic versioning (semver.org 2.0.0) in Lua", + detailed = [[ + See details in http://semver.org + ]], + license = "MIT", + homepage = "https://github.com/kikito/semver.lua" +} +dependencies = { + "lua >= 5.1" +} + +build = { + type = "none", + install = { + lua = { + "semver.lua" + }, + } +} diff --git a/semver.lua b/semver.lua index 1b84882..23f981e 100644 --- a/semver.lua +++ b/semver.lua @@ -1,5 +1,5 @@ local semver = { - _VERSION = '1.2.0', + _VERSION = '1.2.1', _DESCRIPTION = 'semver for Lua', _URL = 'https://github.com/kikito/semver.lua', _LICENSE = [[ @@ -173,6 +173,9 @@ end -- if a and b are versions, a ^ b means "b is backwards-compatible with a" -- in other words, "it's safe to upgrade from a to b" function mt:__pow(other) + if self.major == 0 then + return self == other + end return self.major == other.major and self.minor <= other.minor end diff --git a/spec/semver_spec.lua b/spec/semver_spec.lua index 93263fd..70bb38b 100644 --- a/spec/semver_spec.lua +++ b/spec/semver_spec.lua @@ -254,6 +254,8 @@ describe('semver', function() describe("^", function() it("true for self", function() assert.is_true(v(1,2,3) ^ v(1,2,3)) + assert.is_true(v(0,1,0) ^ v(0,1,0)) + assert.is_true(v("0.1.1+build0") ^ v(0,1,1)) end) it("different major versions mean it's always unsafe", function() assert.is_false(v(2,0,0) ^ v(3,0,0)) @@ -273,6 +275,15 @@ describe('semver', function() it("is unsafe to downgrade to an earlier minor version", function() assert.is_false(v(1,5,0) ^ v(1,2,0)) end) + + it("is unsafe to upgrade any pre-1.0 versions", function() + assert.is_false(v("0.0.1-alpha") ^ v(0,0,1)) + assert.is_false(v("0.0.1") ^ v(0,0,2)) + assert.is_false(v("0.0.1+build0") ^ v(0,0,2)) + assert.is_false(v(0,0,1) ^ v(0,1,0)) + assert.is_false(v(0,0,1) ^ v(1,0,0)) + assert.is_false(v(0,0,1) ^ v("1.0.0-alpha")) + end) end) describe("_VERSION", function()