2024-11-12 14:52:17 +00:00
|
|
|
local frktest = require("@pkg/frktest")
|
2024-11-04 06:48:52 +00:00
|
|
|
local check = frktest.assert.check
|
|
|
|
|
|
|
|
local Option = require("../luau_packages/option")
|
|
|
|
type Option<T> = Option.Option<T>
|
|
|
|
|
|
|
|
local Semver = require("../lib")
|
|
|
|
|
2024-12-02 11:07:59 +00:00
|
|
|
return function(test: typeof(frktest.test))
|
2024-11-21 18:40:10 +00:00
|
|
|
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()
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
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)
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
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()
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
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)
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
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()
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
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)
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
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()
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
-- 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)
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
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()
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
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)
|
2024-11-04 06:48:52 +00:00
|
|
|
end
|