prereleases and builds now working 100% like the spec

This commit is contained in:
Enrique García Cota
2012-01-15 13:30:24 +01:00
parent b1d083e382
commit 48ecb3b539
2 changed files with 63 additions and 24 deletions

View File

@@ -26,10 +26,13 @@ context('semver', function()
end)
it('parses prereleases', function()
checkVersion(v(1,2,3,"-alpha"), 1,2,3,"alpha")
checkVersion(v(1,2,3,"alpha"), 1,2,3,"alpha")
end)
it('parses builds', function()
checkVersion(v(1,2,3,"+build.1"), 1,2,3,nil,"build.1")
checkVersion(v(1,2,3,nil,"build.1"), 1,2,3,nil,"build.1")
end)
it('parses prereleases + builds', function()
checkVersion(v(1,2,3,"alpha","build.1"), 1,2,3,"alpha","build.1")
end)
end)
@@ -52,6 +55,9 @@ context('semver', function()
test("1.2.3+build.15", function()
checkVersion( v'1.2.3+build.15', 1,2,3,nil,'build.15' )
end)
test("1.2.3-rc1+build.15", function()
checkVersion( v'1.2.3-rc1+build.15', 1,2,3,'rc1','build.15' )
end)
end)
describe('errors', function()
@@ -80,6 +86,12 @@ context('semver', function()
test('a non-string or number is passed', function()
assert_error(function() v({}) end)
end)
test('an invalid prerelease', function()
assert_error(function() v'1.2.3-%?' end)
end)
test('an invalid build', function()
assert_error(function() v'1.2.3+%?' end)
end)
end)
end)
@@ -89,10 +101,13 @@ 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)
it("works with a build", function()
assert_equal("1.2.3+foobar", tostring(v(1,2,3, '+foobar')))
assert_equal("1.2.3+foobar", tostring(v(1,2,3,nil,'foobar')))
end)
it("works with a prerelease and a build", function()
assert_equal("1.2.3-alpha+foobar", tostring(v'1.2.3-alpha+foobar'))
end)
end)
@@ -181,6 +196,10 @@ context('semver', function()
assert_less_than(v'1.3.7+build.2.b8f12d7', v'1.3.7+build.11.e0f985a')
end)
end)
test("prereleases + builds", function()
assert_less_than(v'1.0.0-rc.1', v'1.0.0-rc.1+build.1')
assert_less_than(v'1.0.0-rc.1+build.1', v'1.0.0')
end)
end)
describe("nextPatch", function()
@@ -193,8 +212,8 @@ context('semver', function()
it("increases the minor number by 1", function()
assert_equal(v'1.2.0', v'1.1.0':nextMinor())
end)
it("resets the patch number", function()
assert_equal(v'1.2.0', v'1.1.7':nextMinor())
it("resets the patch number, prerelease and build", function()
assert_equal(v'1.2.0', v'1.1.7-a+b':nextMinor())
end)
end)
@@ -202,8 +221,8 @@ context('semver', function()
it("increases the major number by 1", function()
assert_equal(v'2.0.0', v'1.0.0':nextMajor())
end)
it("resets the patch number", function()
assert_equal(v'2.0.0', v'1.2.3':nextMajor())
it("resets the minor, patch, prerelease and build", function()
assert_equal(v'2.0.0', v'1.2.3-a+b':nextMajor())
end)
end)
@@ -220,9 +239,11 @@ context('semver', function()
assert_false(v(2,0,0) ^ v(1,0,0))
end)
test("patch versions are always compatible", function()
test("patches, prereleases and builds are ignored", function()
assert_true(v(1,2,3) ^ v(1,2,0))
assert_true(v(1,2,3) ^ v(1,2,5))
assert_true(v(1,2,3,'foo') ^ v(1,2,3))
assert_true(v(1,2,3,nil,'bar') ^ v(1,2,3))
end)
test("it's safe to upgrade to a newer minor version", function()