Skip to content

Commit

Permalink
chore(tests): include basic stringification tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CompeyDev committed Nov 22, 2024
1 parent 5d76e8c commit 5cdd743
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion tests/tostring.luau
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,54 @@ local Semver = require("../lib")

return function()
test.suite("Stringification tests", function()
test.case("A parsed version when stringified should not change", 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"),
},
}

for expectedString, version 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",
Expand Down

0 comments on commit 5cdd743

Please sign in to comment.