mirror of
https://github.com/0x5eal/semver-luau.git
synced 2024-12-13 08:30:36 +00:00
Erica Marigold
56b38d04e0
* Implements an extension to frktest's `lune_console_reporter` for displaying status of individual running test cases and suites -- with colors :O! * Include mechanism for running select tests using the test runner script.
101 lines
3.1 KiB
Text
101 lines
3.1 KiB
Text
local frktest = require("@pkg/frktest")
|
|
local check = frktest.assert.check
|
|
|
|
local Option = require("../luau_packages/option")
|
|
type Option<T> = Option.Option<T>
|
|
|
|
local Semver = require("../lib")
|
|
|
|
return function(test: typeof(frktest.test))
|
|
test.suite("Semver comparison tests", function()
|
|
test.case("Basic version comparisons", function()
|
|
local v1 = Semver.parse("1.2.3"):unwrap()
|
|
local v2 = Semver.parse("1.2.4"):unwrap()
|
|
local v3 = Semver.parse("1.3.0"):unwrap()
|
|
local v4 = Semver.parse("2.0.0"):unwrap()
|
|
local v5 = Semver.parse("2.1.0"):unwrap()
|
|
local v6 = Semver.parse("3.0.0"):unwrap()
|
|
|
|
check.is_true(v1 < v2)
|
|
check.is_true(v2 < v3)
|
|
check.is_true(v3 < v4)
|
|
check.is_true(v4 < v5)
|
|
check.is_true(v5 < v6)
|
|
check.is_true(v1 <= v2)
|
|
check.is_true(v2 > v1)
|
|
check.is_true(v4 >= v3)
|
|
check.is_true(v6 > v1)
|
|
end)
|
|
|
|
test.case("Equal version comparisons", function()
|
|
local v1 = Semver.parse("1.2.3"):unwrap()
|
|
local v2 = Semver.parse("1.2.3"):unwrap()
|
|
local v3 = Semver.parse("1.2.3"):unwrap()
|
|
local v4 = Semver.parse("1.2.3"):unwrap()
|
|
|
|
check.is_true(v1 == v2)
|
|
check.is_true(v2 == v3)
|
|
check.is_true(v3 == v4)
|
|
check.is_true(v1 <= v2)
|
|
check.is_true(v1 >= v2)
|
|
check.is_false(v1 < v2)
|
|
check.is_false(v1 > v2)
|
|
check.is_false(v3 > v4)
|
|
end)
|
|
|
|
test.case("Prerelease version comparisons", function()
|
|
local v1 = Semver.parse("1.2.3-alpha.1"):unwrap()
|
|
local v2 = Semver.parse("1.2.3-alpha.2"):unwrap()
|
|
local v3 = Semver.parse("1.2.3-beta.1"):unwrap()
|
|
local v4 = Semver.parse("1.2.3"):unwrap()
|
|
local v5 = Semver.parse("1.2.3-rc.1"):unwrap()
|
|
local v6 = Semver.parse("1.2.3-rc.2"):unwrap()
|
|
|
|
check.is_true(v1 < v2)
|
|
check.is_true(v2 < v3)
|
|
check.is_true(v3 < v4)
|
|
check.is_true(v3 < v5)
|
|
check.is_true(v5 < v6)
|
|
check.is_true(v6 < v4)
|
|
check.is_false(v4 < v1)
|
|
check.is_true(v4 > v3)
|
|
end)
|
|
|
|
test.case("Build metadata comparisons", function()
|
|
local v1 = Semver.parse("1.2.3+build.1"):unwrap()
|
|
local v2 = Semver.parse("1.2.3+build.2"):unwrap()
|
|
local v3 = Semver.parse("1.2.3+build.123"):unwrap()
|
|
local v4 = Semver.parse("1.2.3+20230615"):unwrap()
|
|
local v5 = Semver.parse("1.2.3+exp.sha.5114f85"):unwrap()
|
|
|
|
-- Build metadata should be ignored in comparisons
|
|
check.is_true(v1 == v2)
|
|
check.is_true(v2 == v3)
|
|
check.is_true(v3 == v4)
|
|
check.is_true(v4 == v5)
|
|
check.is_false(v1 < v2)
|
|
check.is_false(v2 > v3)
|
|
check.is_false(v4 > v5)
|
|
end)
|
|
|
|
test.case("Complex version comparisons", function()
|
|
local v1 = Semver.parse("2.0.0-alpha.1+build.123"):unwrap()
|
|
local v2 = Semver.parse("2.0.0-beta.1+build.123"):unwrap()
|
|
local v3 = Semver.parse("2.0.0+build.123"):unwrap()
|
|
local v4 = Semver.parse("2.1.0-alpha.1"):unwrap()
|
|
local v5 = Semver.parse("2.1.0"):unwrap()
|
|
local v6 = Semver.parse("2.1.0-rc.1+build.999"):unwrap()
|
|
local v7 = Semver.parse("2.1.1-alpha.1+sha.xyz"):unwrap()
|
|
|
|
check.is_true(v1 < v2)
|
|
check.is_true(v2 < v3)
|
|
check.is_true(v3 < v4)
|
|
check.is_true(v4 < v5)
|
|
check.is_true(v4 < v6)
|
|
check.is_true(v6 < v5)
|
|
check.is_true(v5 < v7)
|
|
check.is_false(v5 < v1)
|
|
check.is_false(v7 < v6)
|
|
end)
|
|
end)
|
|
end
|