2024-11-12 14:53:51 +00:00
|
|
|
local frktest = require("@pkg/frktest")
|
2024-11-04 06:48:52 +00:00
|
|
|
local test = frktest.test
|
|
|
|
local check = frktest.assert.check
|
|
|
|
|
|
|
|
local Option = require("../luau_packages/option")
|
|
|
|
type Option<T> = Option.Option<T>
|
|
|
|
|
|
|
|
local Semver = require("../lib")
|
|
|
|
|
|
|
|
return function()
|
2024-11-21 18:40:10 +00:00
|
|
|
test.suite("Basic tests", function()
|
|
|
|
test.case("Semver creates valid version objects", function()
|
|
|
|
local res = Semver.parse("1.2.3-beta.1")
|
|
|
|
check.is_true(res:isOk())
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
local version = res:unwrap()
|
|
|
|
check.equal(version.major, 1)
|
|
|
|
check.equal(version.minor, 2)
|
|
|
|
check.equal(version.patch, 3)
|
|
|
|
end)
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
test.case("Semver handles prerelease versions", function()
|
|
|
|
local res = Semver.parse("1.2.3-beta.1")
|
|
|
|
check.is_true(res:isOk())
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
local version = res:unwrap()
|
|
|
|
check.equal(version.major, 1)
|
|
|
|
check.equal(version.minor, 2)
|
|
|
|
check.equal(version.patch, 3)
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
check.table.equal(
|
|
|
|
version.prerelease,
|
|
|
|
Option.Some({
|
|
|
|
type = "beta",
|
|
|
|
ordinal = Option.Some(1),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
end)
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
test.case("Semver handles build metadata", function()
|
|
|
|
local res = Semver.parse("1.2.3+build.123")
|
|
|
|
check.is_true(res:isOk())
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
local version = res:unwrap()
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
check.equal(version.major, 1)
|
|
|
|
check.equal(version.minor, 2)
|
|
|
|
check.equal(version.patch, 3)
|
|
|
|
check.table.equal(version.buildMetadata, Option.Some("build.123"))
|
|
|
|
end)
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
test.case("Semver handles prerelease versions with build metadata", function()
|
|
|
|
local res = Semver.parse("1.2.3-beta.1+build.123")
|
|
|
|
check.is_true(res:isOk())
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
local version = res:unwrap()
|
|
|
|
check.equal(version.major, 1)
|
|
|
|
check.equal(version.minor, 2)
|
|
|
|
check.equal(version.patch, 3)
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
check.table.equal(
|
|
|
|
version.prerelease,
|
|
|
|
Option.Some({
|
|
|
|
type = "beta",
|
|
|
|
ordinal = Option.Some(1),
|
|
|
|
})
|
|
|
|
)
|
2024-11-04 06:48:52 +00:00
|
|
|
|
2024-11-21 18:40:10 +00:00
|
|
|
check.table.equal(version.buildMetadata, Option.Some("build.123"))
|
|
|
|
end)
|
|
|
|
end)
|
2024-11-04 06:48:52 +00:00
|
|
|
end
|