mirror of
https://github.com/TangentFoxy/semver.lua.git
synced 2025-07-28 11:02:21 +00:00
Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a4b708ba24 | ||
|
e75daccd6d | ||
|
37d184fe00 | ||
|
0c868789e8 | ||
|
af495adc85 | ||
|
8d88140533 | ||
|
42a67e2d22 | ||
|
2023667d33 | ||
|
c24516b129 | ||
|
35c69808f5 | ||
|
0732da8fdb | ||
|
91b5f6a0d5 | ||
|
4fe61cd502 | ||
|
84e37a1993 | ||
|
f558f99022 | ||
|
9a8f4e2a44 | ||
|
fd8229383a | ||
|
b1e69c953d | ||
|
b06f1f0dad | ||
|
2a8c3aafc5 | ||
|
96e9981520 | ||
|
b992dd69ab | ||
|
7f215c7751 | ||
|
f781e751ab | ||
|
46c275c553 |
37
.travis.yml
Normal file
37
.travis.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
language: erlang
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- LUAROCKS_BASE=luarocks-2.0.9
|
||||||
|
matrix:
|
||||||
|
- LUA=lua5.1 LUA_DEV=liblua5.1-dev LUA_VER=5.1 LUA_SFX=5.1 LUA_INCDIR=/usr/include/lua5.1
|
||||||
|
- LUA=lua5.2 LUA_DEV=liblua5.2-dev LUA_VER=5.2 LUA_SFX=5.2 LUA_INCDIR=/usr/include/lua5.2
|
||||||
|
- LUA=luajit LUA_DEV=libluajit-5.1-dev LUA_VER=5.1 LUA_SFX=jit LUA_INCDIR=/usr/include/luajit-2.0
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- if [ $LUA = "luajit" ]; then
|
||||||
|
sudo add-apt-repository ppa:mwild1/ppa -y && sudo apt-get update -y;
|
||||||
|
fi
|
||||||
|
- sudo apt-get install $LUA
|
||||||
|
- sudo apt-get install $LUA_DEV
|
||||||
|
- lua$LUA_SFX -v
|
||||||
|
# Install a recent luarocks release
|
||||||
|
- wget http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz
|
||||||
|
- tar zxvpf $LUAROCKS_BASE.tar.gz
|
||||||
|
- cd $LUAROCKS_BASE
|
||||||
|
- ./configure
|
||||||
|
--lua-version=$LUA_VER --lua-suffix=$LUA_SFX --with-lua-include="$LUA_INCDIR"
|
||||||
|
- sudo make
|
||||||
|
- sudo make install
|
||||||
|
- cd $TRAVIS_BUILD_DIR
|
||||||
|
|
||||||
|
install:
|
||||||
|
- sudo -E luarocks install busted
|
||||||
|
|
||||||
|
script:
|
||||||
|
- sudo -E busted -v
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email:
|
||||||
|
on_success: change
|
||||||
|
on_failure: always
|
@@ -1,12 +1,14 @@
|
|||||||
h1. semver.lua
|
# semver.lua
|
||||||
|
|
||||||
|
[](https://travis-ci.org/kikito/semver.lua)
|
||||||
|
|
||||||
Semantic versioning for Lua.
|
Semantic versioning for Lua.
|
||||||
|
|
||||||
See http://semver.org/ for details about semantic versioning.
|
See http://semver.org/ for details about semantic versioning.
|
||||||
|
|
||||||
h1. Documentation
|
# Documentation
|
||||||
|
|
||||||
<pre class="lua">
|
``` lua
|
||||||
local v = require 'semver'
|
local v = require 'semver'
|
||||||
|
|
||||||
-- two ways of creating it: with separate parameters, or with one string
|
-- two ways of creating it: with separate parameters, or with one string
|
||||||
@@ -38,7 +40,7 @@ d.build -- 'no.extensions.22'
|
|||||||
v'1.2.3' == v(1,2,3) -- true
|
v'1.2.3' == v(1,2,3) -- true
|
||||||
v'1.2.3' < v(4,5,6) -- true
|
v'1.2.3' < v(4,5,6) -- true
|
||||||
v'1.2.3-alpha' < v'1.2.3' -- true
|
v'1.2.3-alpha' < v'1.2.3' -- true
|
||||||
v'1.2.3' < v'1.2.3-build.1' -- true
|
v'1.2.3' < v'1.2.3+build.1' -- false, builds are ignored when comparing versions in semver
|
||||||
-- (see the "notes" section for more informaion about version comparison)
|
-- (see the "notes" section for more informaion about version comparison)
|
||||||
|
|
||||||
-- "pessimistic upgrade" operator: ^
|
-- "pessimistic upgrade" operator: ^
|
||||||
@@ -52,38 +54,54 @@ v(1,0,0):nextPatch() -- v1.0.1
|
|||||||
v(1,2,3):nextMinor() -- v1.3.0 . Notice the patch resets to 0
|
v(1,2,3):nextMinor() -- v1.3.0 . Notice the patch resets to 0
|
||||||
v(1,2,3):nextMajor() -- v2.0.0 . Minor and patch are reset to 0
|
v(1,2,3):nextMajor() -- v2.0.0 . Minor and patch are reset to 0
|
||||||
|
|
||||||
</pre>
|
```
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
|
||||||
h1. Installation
|
Just copy the semver.lua file wherever you want it (for example on a lib/ folder). Then write this in any Lua file where you want to use it. You must assign the require to a global or local variable (I use a local `v`):
|
||||||
|
|
||||||
Just copy the semver.lua file wherever you want it (for example on a lib/ folder). Then write this in any Lua file where you want to use it. You must assign the require to a global or local variable (I use a local @v@):
|
``` lua
|
||||||
|
local v = require 'semver'
|
||||||
|
```
|
||||||
|
|
||||||
<pre>local v = require 'semver'</pre>
|
Using `v` allows for the nice string syntax: `v'1.2.3-alpha'`.
|
||||||
|
|
||||||
Using @v@ allows for the nice string syntax: @v'1.2.3-alpha'@.
|
|
||||||
|
|
||||||
The @package.path@ variable must be configured so that the folder in which middleclass.lua is copied is available, of course.
|
|
||||||
|
|
||||||
Please make sure that you read the license, too (for your convenience it's now included at the beginning of the semver.lua file).
|
Please make sure that you read the license, too (for your convenience it's now included at the beginning of the semver.lua file).
|
||||||
|
|
||||||
h1. Notes about version comparison
|
# Notes about version comparison
|
||||||
|
|
||||||
Version comparison is done according to the specs:
|
Version comparison is done according to the semver 2.0.0 specs:
|
||||||
|
|
||||||
Major, minor, and patch versions are always compared numerically.
|
Major, minor, and patch versions are always compared numerically.
|
||||||
|
|
||||||
Pre-release and build version precedence MUST be determined by comparing each dot-separated identifier as follows:
|
Pre-release precedence MUST be determined by comparing each dot-separated identifier as follows:
|
||||||
|
|
||||||
* Identifiers consisting of only digits are compared numerically
|
* Identifiers consisting of only digits are compared numerically
|
||||||
* Identifiers with letters or dashes are compared lexically in ASCII sort order.
|
* Identifiers with letters or dashes are compared lexically in ASCII sort order.
|
||||||
* Numeric identifiers always have lower precedence than non-numeric identifiers
|
* Numeric identifiers always have lower precedence than non-numeric identifiers
|
||||||
|
|
||||||
h1. Specs
|
Builds are ignored when calculating precedence: version 1.2.3 and 1.2.3+build5 are considered equal.
|
||||||
|
|
||||||
This project uses "telescope":https://github.com/norman/telescope for its specs. If you want to run the specs, you will have to install telescope first. Then just execute the following from the root inspect folder:
|
# Specs
|
||||||
|
|
||||||
<pre>
|
This project uses [`busted`](https://lunarmodules.github.io/busted/) for its specs. If you want to run the specs, you will have to install telescope first. Then just execute the following from the root inspect folder:
|
||||||
tsc -f spec/*
|
|
||||||
</pre>
|
```
|
||||||
|
busted
|
||||||
|
```
|
||||||
|
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
## v1.1.1:
|
||||||
|
* Removed global variable which was declared by mistake
|
||||||
|
* Changed spec tool from telescope to busted
|
||||||
|
* Changed README format from textile to markdown
|
||||||
|
|
||||||
|
## v.1.2.0:
|
||||||
|
* Fix error: builds were being used for comparison, but according with semver 2.0.0 they should be ignored (so v'1.0.0+build1' is equal to v'1.0.0+build2')
|
||||||
|
* Fix several errors and inconsistencies in the way the comparisons where implemented.
|
||||||
|
* Added a lot more tests to cover more edge cases when comparing versions
|
||||||
|
|
||||||
|
## v.1.2.1
|
||||||
|
* Fix error on pessimistic update operator when applied to a 0.x.x version
|
||||||
|
|
25
rockspecs/semver-1.1.0-1.rockspec
Normal file
25
rockspecs/semver-1.1.0-1.rockspec
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package = "semver"
|
||||||
|
version = "1.1.0-1"
|
||||||
|
source = {
|
||||||
|
url = "git://github.com/kikito/semver.lua.git",
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
summary = "An implementation of semantic versioning (semver.org) 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"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
25
rockspecs/semver-1.1.1-1.rockspec
Normal file
25
rockspecs/semver-1.1.1-1.rockspec
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package = "semver"
|
||||||
|
version = "1.1.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"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
25
rockspecs/semver-1.2.0-1.rockspec
Normal file
25
rockspecs/semver-1.2.0-1.rockspec
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package = "semver"
|
||||||
|
version = "1.2.0-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"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
25
rockspecs/semver-1.2.1-1.rockspec
Normal file
25
rockspecs/semver-1.2.1-1.rockspec
Normal file
@@ -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"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
114
semver.lua
114
semver.lua
@@ -1,10 +1,32 @@
|
|||||||
-- semver.lua - v1.1.0 (2012-01)
|
local semver = {
|
||||||
-- Copyright (c) 2012 Enrique García Cota
|
_VERSION = '1.2.1',
|
||||||
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
_DESCRIPTION = 'semver for Lua',
|
||||||
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
_URL = 'https://github.com/kikito/semver.lua',
|
||||||
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
_LICENSE = [[
|
||||||
-- See http://semver.org for details
|
MIT LICENSE
|
||||||
local version = {}
|
|
||||||
|
Copyright (c) 2015 Enrique García Cota
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of tother software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
|
||||||
local function checkPositiveInteger(number, name)
|
local function checkPositiveInteger(number, name)
|
||||||
assert(number >= 0, name .. ' must be a valid positive number')
|
assert(number >= 0, name .. ' must be a valid positive number')
|
||||||
@@ -17,6 +39,7 @@ end
|
|||||||
|
|
||||||
-- splitByDot("a.bbc.d") == {"a", "bbc", "d"}
|
-- splitByDot("a.bbc.d") == {"a", "bbc", "d"}
|
||||||
local function splitByDot(str)
|
local function splitByDot(str)
|
||||||
|
str = str or ""
|
||||||
local t, count = {}, 0
|
local t, count = {}, 0
|
||||||
str:gsub("([^%.]+)", function(c)
|
str:gsub("([^%.]+)", function(c)
|
||||||
count = count + 1
|
count = count + 1
|
||||||
@@ -45,7 +68,7 @@ end
|
|||||||
|
|
||||||
local function parseBuild(buildWithSign)
|
local function parseBuild(buildWithSign)
|
||||||
if buildWithSign then
|
if buildWithSign then
|
||||||
build = buildWithSign:match("^%+(%w[%.%w-]*)$")
|
local build = buildWithSign:match("^%+(%w[%.%w-]*)$")
|
||||||
assert(build, ("The build %q is not a + sign followed by alphanumerics, dots and slashes"):format(buildWithSign))
|
assert(build, ("The build %q is not a + sign followed by alphanumerics, dots and slashes"):format(buildWithSign))
|
||||||
return build
|
return build
|
||||||
end
|
end
|
||||||
@@ -76,49 +99,59 @@ local function compare(a,b)
|
|||||||
return a == b and 0 or a < b and -1 or 1
|
return a == b and 0 or a < b and -1 or 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local function compareIds(selfId, otherId)
|
local function compareIds(myId, otherId)
|
||||||
if not selfId and not otherId then return 0
|
if myId == otherId then return 0
|
||||||
elseif not selfId then return 1
|
elseif not myId then return -1
|
||||||
elseif not otherId then return -1
|
elseif not otherId then return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local selfNumber, otherNumber = tonumber(selfId), tonumber(otherId)
|
local selfNumber, otherNumber = tonumber(myId), tonumber(otherId)
|
||||||
|
|
||||||
if selfNumber and otherNumber then -- numerical comparison
|
if selfNumber and otherNumber then -- numerical comparison
|
||||||
return compare(selfNumber, otherNumber)
|
return compare(selfNumber, otherNumber)
|
||||||
elseif selfNumber then -- numericals are always smaller than alphanums
|
-- numericals are always smaller than alphanums
|
||||||
|
elseif selfNumber then
|
||||||
return -1
|
return -1
|
||||||
|
elseif otherNumber then
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
return compare(selfId, otherId) -- alphanumerical comparison
|
return compare(myId, otherId) -- alphanumerical comparison
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function smallerPrereleaseOrBuild(mine, his)
|
local function smallerIdList(myIds, otherIds)
|
||||||
if mine == his then return false end
|
|
||||||
|
|
||||||
local myIds, hisIds = splitByDot(mine), splitByDot(his)
|
|
||||||
local myLength = #myIds
|
local myLength = #myIds
|
||||||
local comparison
|
local comparison
|
||||||
|
|
||||||
for i = 1, myLength do
|
for i=1, myLength do
|
||||||
comparison = compareIds(myIds[i], hisIds[i])
|
comparison = compareIds(myIds[i], otherIds[i])
|
||||||
if comparison ~= 0 then return comparison == -1 end
|
if comparison ~= 0 then
|
||||||
|
return comparison == -1
|
||||||
|
end
|
||||||
-- if comparison == 0, continue loop
|
-- if comparison == 0, continue loop
|
||||||
end
|
end
|
||||||
|
|
||||||
return myLength < #hisIds
|
return myLength < #otherIds
|
||||||
|
end
|
||||||
|
|
||||||
|
local function smallerPrerelease(mine, other)
|
||||||
|
if mine == other or not mine then return false
|
||||||
|
elseif not other then return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return smallerIdList(splitByDot(mine), splitByDot(other))
|
||||||
end
|
end
|
||||||
|
|
||||||
local methods = {}
|
local methods = {}
|
||||||
|
|
||||||
function methods:nextMajor()
|
function methods:nextMajor()
|
||||||
return version(self.major + 1, 0, 0)
|
return semver(self.major + 1, 0, 0)
|
||||||
end
|
end
|
||||||
function methods:nextMinor()
|
function methods:nextMinor()
|
||||||
return version(self.major, self.minor + 1, 0)
|
return semver(self.major, self.minor + 1, 0)
|
||||||
end
|
end
|
||||||
function methods:nextPatch()
|
function methods:nextPatch()
|
||||||
return version(self.major, self.minor, self.patch + 1)
|
return semver(self.major, self.minor, self.patch + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
local mt = { __index = methods }
|
local mt = { __index = methods }
|
||||||
@@ -126,19 +159,23 @@ function mt:__eq(other)
|
|||||||
return self.major == other.major and
|
return self.major == other.major and
|
||||||
self.minor == other.minor and
|
self.minor == other.minor and
|
||||||
self.patch == other.patch and
|
self.patch == other.patch and
|
||||||
self.prerelease == other.prerelease and
|
self.prerelease == other.prerelease
|
||||||
self.build == other.build
|
-- notice that build is ignored for precedence in semver 2.0.0
|
||||||
end
|
end
|
||||||
function mt:__lt(other)
|
function mt:__lt(other)
|
||||||
return self.major < other.major or
|
if self.major ~= other.major then return self.major < other.major end
|
||||||
self.minor < other.minor or
|
if self.minor ~= other.minor then return self.minor < other.minor end
|
||||||
self.patch < other.patch or
|
if self.patch ~= other.patch then return self.patch < other.patch end
|
||||||
(self.prerelease and not other.prerelease) or
|
return smallerPrerelease(self.prerelease, other.prerelease)
|
||||||
smallerPrereleaseOrBuild(self.prerelease, other.prerelease) or
|
-- notice that build is ignored for precedence in semver 2.0.0
|
||||||
(not self.build and other.build) or
|
|
||||||
smallerPrereleaseOrBuild(self.build, other.build)
|
|
||||||
end
|
end
|
||||||
|
-- This works like the "pessimisstic operator" in Rubygems.
|
||||||
|
-- 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)
|
function mt:__pow(other)
|
||||||
|
if self.major == 0 then
|
||||||
|
return self == other
|
||||||
|
end
|
||||||
return self.major == other.major and
|
return self.major == other.major and
|
||||||
self.minor <= other.minor
|
self.minor <= other.minor
|
||||||
end
|
end
|
||||||
@@ -166,8 +203,7 @@ local function new(major, minor, patch, prerelease, build)
|
|||||||
return setmetatable(result, mt)
|
return setmetatable(result, mt)
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(version, { __call = function(_, ...) return new(...) end })
|
setmetatable(semver, { __call = function(_, ...) return new(...) end })
|
||||||
|
semver._VERSION= semver(semver._VERSION)
|
||||||
|
|
||||||
version._VERSION = version('1.1.0')
|
return semver
|
||||||
|
|
||||||
return version
|
|
||||||
|
21
spec/custom_assertions.lua
Normal file
21
spec/custom_assertions.lua
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
local assert = require("luassert")
|
||||||
|
local say = require("say")
|
||||||
|
|
||||||
|
local function less(state, arguments)
|
||||||
|
return arguments[1] < arguments[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
local function greater(state, arguments)
|
||||||
|
return arguments[1] > arguments[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
say:set_namespace("en")
|
||||||
|
say:set("assertion.less.positive", "Expected %s to be smaller than %s")
|
||||||
|
say:set("assertion.less.negative", "Expected %s to not be smaller than %s")
|
||||||
|
assert:register("assertion", "less", less, "assertion.less.positive", "assertion.less.negative")
|
||||||
|
|
||||||
|
say:set("assertion.greater.positive", "Expected %s to be greater than %s")
|
||||||
|
say:set("assertion.greater.negative", "Expected %s to not be greater than %s")
|
||||||
|
assert:register("assertion", "greater", greater, "assertion.greater.positive", "assertion.greater.negative")
|
||||||
|
|
||||||
|
|
@@ -1,18 +1,20 @@
|
|||||||
|
require 'spec.custom_assertions'
|
||||||
|
|
||||||
local v = require 'semver'
|
local v = require 'semver'
|
||||||
|
|
||||||
local function checkVersion(ver, major, minor, patch, prerelease, build)
|
local function checkVersion(ver, major, minor, patch, prerelease, build)
|
||||||
assert_equal(major, ver.major)
|
assert.equal(major, ver.major)
|
||||||
assert_equal(minor, ver.minor)
|
assert.equal(minor, ver.minor)
|
||||||
assert_equal(patch, ver.patch)
|
assert.equal(patch, ver.patch)
|
||||||
assert_equal(prerelease, ver.prerelease)
|
assert.equal(prerelease, ver.prerelease)
|
||||||
assert_equal(build, ver.build)
|
assert.equal(build, ver.build)
|
||||||
end
|
end
|
||||||
|
|
||||||
context('semver', function()
|
describe('semver', function()
|
||||||
|
|
||||||
context('creation', function()
|
describe('creation', function()
|
||||||
|
|
||||||
context('from numbers', function()
|
describe('from numbers', function()
|
||||||
it('parses 3 numbers correctly', function()
|
it('parses 3 numbers correctly', function()
|
||||||
checkVersion(v(1,2,3), 1,2,3)
|
checkVersion(v(1,2,3), 1,2,3)
|
||||||
end)
|
end)
|
||||||
@@ -37,230 +39,257 @@ context('semver', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe("from strings", function()
|
describe("from strings", function()
|
||||||
test("1.2.3", function()
|
it("1.2.3", function()
|
||||||
checkVersion( v'1.2.3', 1,2,3)
|
checkVersion( v'1.2.3', 1,2,3)
|
||||||
end)
|
end)
|
||||||
test("10.20.123", function()
|
it("10.20.123", function()
|
||||||
checkVersion( v'10.20.123', 10,20,123)
|
checkVersion( v'10.20.123', 10,20,123)
|
||||||
end)
|
end)
|
||||||
test("2.0", function()
|
it("2.0", function()
|
||||||
checkVersion( v'2.0', 2,0,0)
|
checkVersion( v'2.0', 2,0,0)
|
||||||
end)
|
end)
|
||||||
test("5", function()
|
it("5", function()
|
||||||
checkVersion( v'5', 5,0,0)
|
checkVersion( v'5', 5,0,0)
|
||||||
end)
|
end)
|
||||||
test("1.2.3-alpha", function()
|
it("1.2.3-alpha", function()
|
||||||
checkVersion( v'1.2.3-alpha', 1,2,3,'alpha' )
|
checkVersion( v'1.2.3-alpha', 1,2,3,'alpha' )
|
||||||
end)
|
end)
|
||||||
test("1.2.3+build.15", function()
|
it("1.2.3+build.15", function()
|
||||||
checkVersion( v'1.2.3+build.15', 1,2,3,nil,'build.15' )
|
checkVersion( v'1.2.3+build.15', 1,2,3,nil,'build.15' )
|
||||||
end)
|
end)
|
||||||
test("1.2.3-rc1+build.15", function()
|
it("1.2.3-rc1+build.15", function()
|
||||||
checkVersion( v'1.2.3-rc1+build.15', 1,2,3,'rc1','build.15' )
|
checkVersion( v'1.2.3-rc1+build.15', 1,2,3,'rc1','build.15' )
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('errors', function()
|
describe('errors', function()
|
||||||
test('no parameters are passed', function()
|
it('no parameters are passed', function()
|
||||||
assert_error(function() v() end)
|
assert.error(function() v() end)
|
||||||
end)
|
end)
|
||||||
test('negative numbers', function()
|
it('negative numbers', function()
|
||||||
assert_error(function() v(-1, 0, 0) end)
|
assert.error(function() v(-1, 0, 0) end)
|
||||||
assert_error(function() v( 0,-1, 0) end)
|
assert.error(function() v( 0,-1, 0) end)
|
||||||
assert_error(function() v( 0, 0,-1) end)
|
assert.error(function() v( 0, 0,-1) end)
|
||||||
end)
|
end)
|
||||||
test('floats', function()
|
it('floats', function()
|
||||||
assert_error(function() v(.1, 0, 0) end)
|
assert.error(function() v(.1, 0, 0) end)
|
||||||
assert_error(function() v( 0,.1, 0) end)
|
assert.error(function() v( 0,.1, 0) end)
|
||||||
assert_error(function() v( 0, 0,.1) end)
|
assert.error(function() v( 0, 0,.1) end)
|
||||||
end)
|
end)
|
||||||
test('empty string', function()
|
it('empty string', function()
|
||||||
assert_error(function() v("") end)
|
assert.error(function() v("") end)
|
||||||
end)
|
end)
|
||||||
test('garbage at the beginning of the string', function()
|
it('garbage at the beginning of the string', function()
|
||||||
assert_error(function() v("foobar1.2.3") end)
|
assert.error(function() v("foobar1.2.3") end)
|
||||||
end)
|
end)
|
||||||
test('garbage at the end of the string', function()
|
it('garbage at the end of the string', function()
|
||||||
assert_error(function() v("1.2.3foobar") end)
|
assert.error(function() v("1.2.3foobar") end)
|
||||||
end)
|
end)
|
||||||
test('a non-string or number is passed', function()
|
it('a non-string or number is passed', function()
|
||||||
assert_error(function() v({}) end)
|
assert.error(function() v({}) end)
|
||||||
end)
|
end)
|
||||||
test('an invalid prerelease', function()
|
it('an invalid prerelease', function()
|
||||||
assert_error(function() v'1.2.3-%?' end)
|
assert.error(function() v'1.2.3-%?' end)
|
||||||
end)
|
end)
|
||||||
test('an invalid build', function()
|
it('an invalid build', function()
|
||||||
assert_error(function() v'1.2.3+%?' end)
|
assert.error(function() v'1.2.3+%?' end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("tostring", function()
|
describe("tostring", function()
|
||||||
it("works with major, minor and patch", function()
|
it("works with major, minor and patch", function()
|
||||||
assert_equal("1.2.3", tostring(v(1,2,3)))
|
assert.equal("1.2.3", tostring(v(1,2,3)))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("works with a prerelease", function()
|
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)
|
||||||
it("works with a build", function()
|
it("works with a build", function()
|
||||||
assert_equal("1.2.3+foobar", tostring(v(1,2,3,nil,'foobar')))
|
assert.equal("1.2.3+foobar", tostring(v(1,2,3,nil,'foobar')))
|
||||||
end)
|
end)
|
||||||
it("works with a prerelease and a build", function()
|
it("works with a prerelease and a build", function()
|
||||||
assert_equal("1.2.3-alpha+foobar", tostring(v'1.2.3-alpha+foobar'))
|
assert.equal("1.2.3-alpha+foobar", tostring(v'1.2.3-alpha+foobar'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("==", function()
|
describe("==", function()
|
||||||
it("is true when major, minor and patch are the same", function()
|
it("is true when major, minor and patch are the same", function()
|
||||||
assert_equal(v(1,2,3), v'1.2.3')
|
assert.equal(v'1.0.0', v'1.0.0')
|
||||||
end)
|
end)
|
||||||
it("is false when major, minor and patch are not the same", function()
|
it("is false when major, minor, patch or prerelease are not the same", function()
|
||||||
assert_not_equal(v(1,2,3), v(4,5,6))
|
assert.not_equal(v'1.0.0', v'1.0.1')
|
||||||
|
assert.not_equal(v'1.0.0', v'1.1.0')
|
||||||
|
assert.not_equal(v'1.0.0', v'2.0.0')
|
||||||
|
assert.not_equal(v'1.0.0', v'1.0.0-alpha')
|
||||||
end)
|
end)
|
||||||
it("false if all is the same except the prerelease", function()
|
it("ignores builds", function()
|
||||||
assert_not_equal(v(1,2,3), v'1.2.3-alpha')
|
assert.equal(v'1.2.3', v'1.2.3+1')
|
||||||
end)
|
assert.equal(v'1.2.3+1', v'1.2.3+2')
|
||||||
it("false if all is the same except the build", function()
|
|
||||||
assert_not_equal(v(1,2,3), v'1.2.3+peter.1')
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("<", function()
|
describe("<", function()
|
||||||
test("true if major < minor", function()
|
it("compares correctly when major, minor and patch are equal", function()
|
||||||
assert_less_than(v'1.100.10', v'2.0.0')
|
assert.not_less(v'1.0.0', v'1.0.0')
|
||||||
|
assert.not_greater(v'1.0.0', v'1.0.0')
|
||||||
|
assert.equal(v'1.0.0', v'1.0.0')
|
||||||
end)
|
end)
|
||||||
test("false if major > minor", function()
|
|
||||||
assert_greater_than(v'2', v'1')
|
it("#focus prioritizes major over minor", function()
|
||||||
|
--assert.less(v'1.100.10', v'2.0.0')
|
||||||
|
assert.not_greater(v'1.100.10', v'2.0.0')
|
||||||
|
--assert.greater(v'2', v'1')
|
||||||
|
--assert.not_less(v'2', v'1')
|
||||||
end)
|
end)
|
||||||
test("true if major = major but minor < minor", function()
|
it("when equal major, compares minor", function()
|
||||||
assert_less_than(v'1.2.0', v'1.3.0')
|
assert.less(v'1.2.0', v'1.3.0')
|
||||||
|
assert.not_greater(v'1.2.0', v'1.3.0')
|
||||||
|
assert.greater(v'1.1', v'1.0')
|
||||||
|
assert.not_less(v'1.1', v'1.0')
|
||||||
end)
|
end)
|
||||||
test("false if minor < minor", function()
|
it("when equal major and minor, compares patch", function()
|
||||||
assert_greater_than(v'1.1', v'1.0')
|
assert.less(v'0.0.1', v'0.0.10')
|
||||||
end)
|
assert.not_greater(v'0.0.1', v'0.0.10')
|
||||||
test("true if major =, minor =, but patch <", function()
|
assert.greater(v'0.0.2', v'0.0.1')
|
||||||
assert_less_than(v'0.0.1', v'0.0.10')
|
assert.not_less(v'0.0.2', v'0.0.1')
|
||||||
end)
|
|
||||||
test("false if major =, minor =, but patch >", function()
|
|
||||||
assert_greater_than(v'0.0.2', v'0.0.1')
|
|
||||||
end)
|
end)
|
||||||
describe("prereleases", function()
|
describe("prereleases", function()
|
||||||
test("false if exact same prerelease", function()
|
it("compares correctly when major, minor, patch and prerelease are equal", function()
|
||||||
assert_false(v'1.0.0-beta' < v'1.0.0-beta')
|
assert.not_less(v'1.0.0-1', v'1.0.0-1')
|
||||||
|
assert.not_greater(v'1.0.0-1', v'1.0.0-1')
|
||||||
|
assert.equal(v'1.0.0-1', v'1.0.0-1')
|
||||||
end)
|
end)
|
||||||
test("a prerelease version is less than the official version", function()
|
it("prioritizes non-prereleases over prereleases", function()
|
||||||
assert_less_than(v'1.0.0-rc1', v'1.0.0')
|
assert.less(v'1.0.0-rc1', v'1.0.0')
|
||||||
|
assert.not_greater(v'1.0.0-rc1', v'1.0.0')
|
||||||
|
assert.greater(v'1.2.3', v'1.2.3-alpha')
|
||||||
|
assert.not_less(v'1.2.3', v'1.2.3-alpha')
|
||||||
end)
|
end)
|
||||||
test("identifiers with only digits are compared numerically", function()
|
it("compares identifiers with only digits numerically", function()
|
||||||
assert_less_than(v'1.0.0-1', v'1.0.0-2')
|
assert.less(v'1.0.0-1', v'1.0.0-2')
|
||||||
assert_less_than(v'1.0.0-2', v'1.0.0-10')
|
assert.not_greater(v'1.0.0-1', v'1.0.0-2')
|
||||||
|
assert.greater(v'1.0.0-2', v'1.0.0-1')
|
||||||
|
assert.not_less(v'1.0.0-2', v'1.0.0-1')
|
||||||
end)
|
end)
|
||||||
test("itendifiers with letters or dashes are compared lexiconumerically", function()
|
it("compares idendifiers with letters or dashes lexiconumerically", function()
|
||||||
assert_less_than(v'1.0.0-alpha', v'1.0.0-beta')
|
assert.less(v'1.0.0-alpha', v'1.0.0-beta')
|
||||||
assert_less_than(v'1.0.0-alpha-10', v'1.0.0-alpha-2')
|
assert.not_greater(v'1.0.0-alpha', v'1.0.0-beta')
|
||||||
|
assert.less(v'1.0.0-alpha-10', v'1.0.0-alpha-2')
|
||||||
|
assert.not_greater(v'1.0.0-alpha-10', v'1.0.0-alpha-2')
|
||||||
|
assert.greater(v'1.0.0-beta', v'1.0.0-alpha')
|
||||||
|
assert.not_less(v'1.0.0-beta', v'1.0.0-alpha')
|
||||||
|
assert.greater(v'1.0.0-alpha-2', v'1.0.0-alpha-10')
|
||||||
|
assert.not_less(v'1.0.0-alpha-2', v'1.0.0-alpha-10')
|
||||||
end)
|
end)
|
||||||
test("numerical ids always have less priority than lexiconumericals", function()
|
it("prioritizes lexiconumericals over numbers", function()
|
||||||
assert_less_than(v'1.0.0-1', v'1.0.0-alpha')
|
assert.less(v'1.0.0-1', v'1.0.0-alpha')
|
||||||
assert_less_than(v'1.0.0-2', v'1.0.0-1asdf')
|
assert.not_greater(v'1.0.0-1', v'1.0.0-alpha')
|
||||||
|
assert.less(v'1.0.0-2', v'1.0.0-1asdf')
|
||||||
|
assert.not_greater(v'1.0.0-2', v'1.0.0-1asdf')
|
||||||
|
assert.greater(v'1.0.0-alpha', v'1.0.0-1')
|
||||||
|
assert.not_less(v'1.0.0-alpha', v'1.0.0-1')
|
||||||
|
assert.greater(v'1.0.0-1asdf', v'1.0.0-2')
|
||||||
|
assert.not_less(v'1.0.0-1asdf', v'1.0.0-2')
|
||||||
end)
|
end)
|
||||||
test("identifiers can be separated by colons; they must be compared individually", function()
|
it("splits identifiers by colons, comparing every pair individually", function()
|
||||||
assert_less_than(v'1.0.0-alpha', v'1.0.0-alpha.1')
|
assert.less(v'1.0.0-alpha', v'1.0.0-alpha.1')
|
||||||
assert_less_than(v'1.0.0-alpha.1', v'1.0.0-beta.2')
|
assert.not_greater(v'1.0.0-alpha', v'1.0.0-alpha.1')
|
||||||
assert_less_than(v'1.0.0-beta.2', v'1.0.0-beta.11')
|
assert.less(v'1.0.0-alpha.1', v'1.0.0-beta.2')
|
||||||
assert_less_than(v'1.0.0-beta.11', v'1.0.0-rc.1')
|
assert.not_greater(v'1.0.0-alpha.1', v'1.0.0-beta.2')
|
||||||
|
assert.less(v'1.0.0-beta.2', v'1.0.0-beta.11')
|
||||||
|
assert.not_greater(v'1.0.0-beta.2', v'1.0.0-beta.11')
|
||||||
|
assert.less(v'1.0.0-beta.11', v'1.0.0-rc.1')
|
||||||
|
assert.not_greater(v'1.0.0-beta.11', v'1.0.0-rc.1')
|
||||||
|
|
||||||
|
assert.greater(v'1.0.0-alpha.1', v'1.0.0-alpha')
|
||||||
|
assert.not_less(v'1.0.0-alpha.1', v'1.0.0-alpha')
|
||||||
|
assert.greater(v'1.0.0-beta.2', v'1.0.0-alpha.1')
|
||||||
|
assert.not_less(v'1.0.0-beta.2', v'1.0.0-alpha.1')
|
||||||
|
assert.greater(v'1.0.0-beta.11', v'1.0.0-beta.2')
|
||||||
|
assert.not_less(v'1.0.0-beta.11', v'1.0.0-beta.2')
|
||||||
|
assert.greater(v'1.0.0-rc.1', v'1.0.0-beta.11')
|
||||||
|
assert.not_less(v'1.0.0-rc.1', v'1.0.0-beta.11')
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
describe("builds", function()
|
describe("builds", function()
|
||||||
test("false if exact same build", function()
|
it("false independently of the build", function()
|
||||||
assert_false(v'1.0.0+build1' < v'1.0.0+build1')
|
assert.not_less(v'1.0.0+build1', v'1.0.0')
|
||||||
|
assert.not_less(v'1.0.0+build1', v'1.0.0+build3')
|
||||||
|
assert.not_less(v'1.0.0-beta+build1', v'1.0.0-beta+build2')
|
||||||
|
assert.not_greater(v'1.0.0+build1', v'1.0.0')
|
||||||
|
assert.not_greater(v'1.0.0+build1', v'1.0.0+build3')
|
||||||
|
assert.not_greater(v'1.0.0-beta+build1', v'1.0.0-beta+build2')
|
||||||
end)
|
end)
|
||||||
test("a regular (not-build) version is always less than a build version", function()
|
|
||||||
assert_less_than(v'1.0.0', v'1.0.0+12')
|
|
||||||
end)
|
|
||||||
test("identifiers with only digits are compared numerically", function()
|
|
||||||
assert_less_than(v'1.0.0+1', v'1.0.0+2')
|
|
||||||
assert_less_than(v'1.0.0+2', v'1.0.0+10')
|
|
||||||
end)
|
|
||||||
test("idendifiers with letters or dashes are compared lexiconumerically", function()
|
|
||||||
assert_less_than(v'1.0.0+build1', v'1.0.0+build2')
|
|
||||||
assert_less_than(v'1.0.0+build10', v'1.0.0+build2')
|
|
||||||
end)
|
|
||||||
test("numerical ids always have less priority than lexiconumericals", function()
|
|
||||||
assert_less_than(v'1.0.0+1', v'1.0.0+build1')
|
|
||||||
assert_less_than(v'1.0.0+2', v'1.0.0+1build')
|
|
||||||
end)
|
|
||||||
test("identifiers can be separated by colons; they must be compared individually", function()
|
|
||||||
assert_less_than(v'1.0.0+0.3.7', v'1.3.7+build')
|
|
||||||
assert_less_than(v'1.3.7+build', v'1.3.7+build.2.b8f12d7')
|
|
||||||
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)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("nextPatch", function()
|
describe("nextPatch", function()
|
||||||
it("increases the patch number by 1", function()
|
it("increases the patch number by 1", function()
|
||||||
assert_equal(v'1.0.1', v'1.0.0':nextPatch())
|
assert.equal(v'1.0.1', v'1.0.0':nextPatch())
|
||||||
end)
|
end)
|
||||||
it("resets prerelease and build", function()
|
it("resets prerelease and build", function()
|
||||||
assert_equal(v'1.0.1', v'1.0.0-a+b':nextPatch())
|
assert.equal(v'1.0.1', v'1.0.0-a+b':nextPatch())
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("nextMinor", function()
|
describe("nextMinor", function()
|
||||||
it("increases the minor number by 1", function()
|
it("increases the minor number by 1", function()
|
||||||
assert_equal(v'1.2.0', v'1.1.0':nextMinor())
|
assert.equal(v'1.2.0', v'1.1.0':nextMinor())
|
||||||
end)
|
end)
|
||||||
it("resets the patch number, prerelease and build", function()
|
it("resets the patch number, prerelease and build", function()
|
||||||
assert_equal(v'1.2.0', v'1.1.7-a+b':nextMinor())
|
assert.equal(v'1.2.0', v'1.1.7-a+b':nextMinor())
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("nextMajor", function()
|
describe("nextMajor", function()
|
||||||
it("increases the major number by 1", function()
|
it("increases the major number by 1", function()
|
||||||
assert_equal(v'2.0.0', v'1.0.0':nextMajor())
|
assert.equal(v'2.0.0', v'1.0.0':nextMajor())
|
||||||
end)
|
end)
|
||||||
it("resets the minor, patch, prerelease and build", function()
|
it("resets the minor, patch, prerelease and build", function()
|
||||||
assert_equal(v'2.0.0', v'1.2.3-a+b':nextMajor())
|
assert.equal(v'2.0.0', v'1.2.3-a+b':nextMajor())
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
-- This works like the "pessimisstic operator" in Rubygems.
|
|
||||||
-- 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"
|
|
||||||
describe("^", function()
|
describe("^", function()
|
||||||
test("true for self", function()
|
it("true for self", function()
|
||||||
assert_true(v(1,2,3) ^ v(1,2,3))
|
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)
|
end)
|
||||||
test("different major versions mean it's always unsafe", function()
|
it("different major versions mean it's always unsafe", function()
|
||||||
assert_false(v(2,0,0) ^ v(3,0,0))
|
assert.is_false(v(2,0,0) ^ v(3,0,0))
|
||||||
assert_false(v(2,0,0) ^ v(1,0,0))
|
assert.is_false(v(2,0,0) ^ v(1,0,0))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
test("patches, prereleases and builds are ignored", function()
|
it("patches, prereleases and builds are ignored", function()
|
||||||
assert_true(v(1,2,3) ^ v(1,2,0))
|
assert.is_true(v(1,2,3) ^ v(1,2,0))
|
||||||
assert_true(v(1,2,3) ^ v(1,2,5))
|
assert.is_true(v(1,2,3) ^ v(1,2,5))
|
||||||
assert_true(v(1,2,3,'foo') ^ v(1,2,3))
|
assert.is_true(v(1,2,3,'foo') ^ v(1,2,3))
|
||||||
assert_true(v(1,2,3,nil,'bar') ^ v(1,2,3))
|
assert.is_true(v(1,2,3,nil,'bar') ^ v(1,2,3))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
test("it's safe to upgrade to a newer minor version", function()
|
it("is safe to upgrade to a newer minor version", function()
|
||||||
assert_true(v(1,2,0) ^ v(1,5,0))
|
assert.is_true(v(1,2,0) ^ v(1,5,0))
|
||||||
end)
|
end)
|
||||||
test("it's unsafe to downgrade to an earlier minor version", function()
|
it("is unsafe to downgrade to an earlier minor version", function()
|
||||||
assert_false(v(1,5,0) ^ v(1,2,0))
|
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)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("_VERSION", function()
|
describe("_VERSION", function()
|
||||||
it("can be extracted from the lib", function()
|
it("can be extracted from the lib", function()
|
||||||
local x = v._VERSION
|
local x = v._VERSION
|
||||||
assert_equal('table', type(x))
|
assert.equal('table', type(x))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user