mirror of
https://github.com/0x5eal/semver-luau.git
synced 2024-12-12 15:00: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.
82 lines
2.3 KiB
Text
82 lines
2.3 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("Stringification tests", function()
|
|
test.case("A version constructed with new() when stringified should match expected string", function()
|
|
local versionMap: { [string]: Semver.Version } = {
|
|
["1.2.3"] = { major = 1, minor = 2, patch = 3, prerelease = Option.None, buildMetadata = Option.None },
|
|
["1.0.0-alpha"] = {
|
|
major = 1,
|
|
minor = 0,
|
|
patch = 0,
|
|
prerelease = Option.Some({ type = "alpha" :: Semver.PreleaseType, ordinal = Option.None }),
|
|
buildMetadata = Option.None,
|
|
},
|
|
["2.3.4-beta.1"] = {
|
|
major = 2,
|
|
minor = 3,
|
|
patch = 4,
|
|
prerelease = Option.Some({
|
|
type = "beta" :: Semver.PreleaseType,
|
|
ordinal = Option.Some(1),
|
|
}),
|
|
buildMetadata = Option.None,
|
|
},
|
|
["3.0.0-rc.1+build.123"] = {
|
|
major = 3,
|
|
minor = 0,
|
|
patch = 0,
|
|
prerelease = Option.Some({
|
|
type = "rc" :: Semver.PreleaseType,
|
|
ordinal = Option.Some(1),
|
|
}),
|
|
buildMetadata = Option.Some("build.123"),
|
|
},
|
|
["4.5.6+sha.xyz"] = {
|
|
major = 4,
|
|
minor = 5,
|
|
patch = 6,
|
|
prerelease = Option.None,
|
|
buildMetadata = Option.Some("sha.xyz"),
|
|
},
|
|
}
|
|
|
|
-- FIXME: unknown usage here is because these types are too complex for
|
|
-- Luau to typecheck properly, we cast it manually since the above
|
|
-- map is typed properly anyway
|
|
for expectedString, version: unknown in versionMap do
|
|
local constructed = Semver.new(version :: Semver.Version)
|
|
local stringified = tostring(constructed)
|
|
|
|
check.equal(stringified, expectedString)
|
|
end
|
|
end)
|
|
|
|
test.case("A parsed version when stringified should not change in roundtrip", function()
|
|
local versions = {
|
|
"1.2.3",
|
|
"1.0.0-alpha",
|
|
"2.3.4-beta.1",
|
|
"3.0.0-rc.1+build.123",
|
|
"4.5.6+sha.xyz",
|
|
"5.0.0-alpha.1+build.999",
|
|
"6.7.8-beta.2+exp.sha.5114f85",
|
|
"7.0.0-alpha.1",
|
|
"9.9.9+20230615",
|
|
}
|
|
|
|
for _, version in versions do
|
|
local parsed = Semver.parse(version):unwrap()
|
|
local stringified = tostring(parsed)
|
|
|
|
check.equal(stringified, version)
|
|
end
|
|
end)
|
|
end)
|
|
end
|