chore(tests): apply formatting

This commit is contained in:
Erica Marigold 2024-11-21 18:40:10 +00:00
parent 79a4205f4d
commit 9bde66aed4
Signed by: DevComp
GPG key ID: 429EF1C337871656
3 changed files with 165 additions and 165 deletions

View file

@ -8,95 +8,95 @@ type Option<T> = Option.Option<T>
local Semver = require("../lib")
return function()
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()
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)
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()
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)
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()
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)
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()
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)
-- 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()
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)
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

View file

@ -8,65 +8,65 @@ type Option<T> = Option.Option<T>
local Semver = require("../lib")
return function()
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())
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())
local version = res:unwrap()
check.equal(version.major, 1)
check.equal(version.minor, 2)
check.equal(version.patch, 3)
end)
local version = res:unwrap()
check.equal(version.major, 1)
check.equal(version.minor, 2)
check.equal(version.patch, 3)
end)
test.case("Semver handles prerelease versions", function()
local res = Semver.parse("1.2.3-beta.1")
check.is_true(res:isOk())
test.case("Semver handles prerelease versions", function()
local res = Semver.parse("1.2.3-beta.1")
check.is_true(res:isOk())
local version = res:unwrap()
check.equal(version.major, 1)
check.equal(version.minor, 2)
check.equal(version.patch, 3)
local version = res:unwrap()
check.equal(version.major, 1)
check.equal(version.minor, 2)
check.equal(version.patch, 3)
check.table.equal(
version.prerelease,
Option.Some({
type = "beta",
ordinal = Option.Some(1),
})
)
end)
check.table.equal(
version.prerelease,
Option.Some({
type = "beta",
ordinal = Option.Some(1),
})
)
end)
test.case("Semver handles build metadata", function()
local res = Semver.parse("1.2.3+build.123")
check.is_true(res:isOk())
test.case("Semver handles build metadata", function()
local res = Semver.parse("1.2.3+build.123")
check.is_true(res:isOk())
local version = res:unwrap()
local version = res:unwrap()
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)
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)
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())
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())
local version = res:unwrap()
check.equal(version.major, 1)
check.equal(version.minor, 2)
check.equal(version.patch, 3)
local version = res:unwrap()
check.equal(version.major, 1)
check.equal(version.minor, 2)
check.equal(version.patch, 3)
check.table.equal(
version.prerelease,
Option.Some({
type = "beta",
ordinal = Option.Some(1),
})
)
check.table.equal(
version.prerelease,
Option.Some({
type = "beta",
ordinal = Option.Some(1),
})
)
check.table.equal(version.buildMetadata, Option.Some("build.123"))
end)
end)
check.table.equal(version.buildMetadata, Option.Some("build.123"))
end)
end)
end

View file

@ -1,33 +1,33 @@
local frktest = require("@pkg/frktest")
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()
test.suite("Stringification tests", function()
test.case("A parsed version when stringified should not change", 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
local frktest = require("@pkg/frktest")
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()
test.suite("Stringification tests", function()
test.case("A parsed version when stringified should not change", 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