chore(tests): migrate parse_invalid to use official frktest package

This commit is contained in:
Erica Marigold 2024-11-12 20:24:52 +05:30 committed by GitHub
parent fc9a8701f6
commit 727692b31e

View file

@ -1,122 +1,122 @@
local frktest = require("../lune_packages/frktest").core local frktest = require("@pkg/frktest")
local test = frktest.test local test = frktest.test
local check = frktest.assert.check local check = frktest.assert.check
local Semver = require("../lib") local Semver = require("../lib")
return function() return function()
test.suite("Invalid semver parsing tests", function() test.suite("Invalid semver parsing tests", function()
test.case("Rejects missing components", function() test.case("Rejects missing components", function()
local res = Semver.parse("1.2") local res = Semver.parse("1.2")
check.is_true(res:isErr()) check.is_true(res:isErr())
check.table.contains(res:unwrapErr(), { check.table.contains(res:unwrapErr(), {
kind = { kind = {
id = "MandatoryComponentMissing", id = "MandatoryComponentMissing",
components = { "1", "2" }, components = { "1", "2" },
}, },
}) })
end) end)
test.case("Rejects invalid component types", function() test.case("Rejects invalid component types", function()
-- Test invalid major -- Test invalid major
local res = Semver.parse("a.2.3") local res = Semver.parse("a.2.3")
check.is_true(res:isErr()) check.is_true(res:isErr())
check.table.contains(res:unwrapErr(), { check.table.contains(res:unwrapErr(), {
kind = { kind = {
id = "InvalidComponentType", id = "InvalidComponentType",
component = "major", component = "major",
got = "char", got = "char",
}, },
}) })
-- Test invalid minor with symbols -- Test invalid minor with symbols
res = Semver.parse("1.$.3") res = Semver.parse("1.$.3")
check.is_true(res:isErr()) check.is_true(res:isErr())
check.table.contains(res:unwrapErr(), { check.table.contains(res:unwrapErr(), {
kind = { kind = {
id = "InvalidComponentType", id = "InvalidComponentType",
component = "minor", component = "minor",
got = "symbol", got = "symbol",
}, },
}) })
-- Test invalid patch -- Test invalid patch
res = Semver.parse("1.2.x") res = Semver.parse("1.2.x")
check.is_true(res:isErr()) check.is_true(res:isErr())
check.table.contains(res:unwrapErr(), { check.table.contains(res:unwrapErr(), {
kind = { kind = {
id = "InvalidComponentType", id = "InvalidComponentType",
component = "patch", component = "patch",
got = "char", got = "char",
}, },
}) })
end) end)
test.case("Rejects leading zeros", function() test.case("Rejects leading zeros", function()
-- Test leading zeros in major -- Test leading zeros in major
local res = Semver.parse("01.2.3") local res = Semver.parse("01.2.3")
check.is_true(res:isErr()) check.is_true(res:isErr())
check.table.contains(res:unwrapErr(), { check.table.contains(res:unwrapErr(), {
kind = { kind = {
id = "LeadingZerosPresent", id = "LeadingZerosPresent",
component = "major", component = "major",
}, },
}) })
-- Test leading zeros in minor -- Test leading zeros in minor
res = Semver.parse("1.02.3") res = Semver.parse("1.02.3")
check.is_true(res:isErr()) check.is_true(res:isErr())
check.table.contains(res:unwrapErr(), { check.table.contains(res:unwrapErr(), {
kind = { kind = {
id = "LeadingZerosPresent", id = "LeadingZerosPresent",
component = "minor", component = "minor",
}, },
}) })
-- Test leading zeros in patch -- Test leading zeros in patch
res = Semver.parse("1.2.03") res = Semver.parse("1.2.03")
check.is_true(res:isErr()) check.is_true(res:isErr())
check.table.contains(res:unwrapErr(), { check.table.contains(res:unwrapErr(), {
kind = { kind = {
id = "LeadingZerosPresent", id = "LeadingZerosPresent",
component = "patch", component = "patch",
}, },
}) })
end) end)
test.case("Rejects invalid prerelease types", function() test.case("Rejects invalid prerelease types", function()
local res = Semver.parse("1.2.3-gamma.1") local res = Semver.parse("1.2.3-gamma.1")
check.is_true(res:isErr()) check.is_true(res:isErr())
check.table.contains(res:unwrapErr(), { check.table.contains(res:unwrapErr(), {
kind = { kind = {
id = "InvalidPrereleaseType", id = "InvalidPrereleaseType",
type = "gamma", type = "gamma",
}, },
}) })
end) end)
test.case("Rejects invalid prerelease ordinals", function() test.case("Rejects invalid prerelease ordinals", function()
-- Test with character ordinal -- Test with character ordinal
local res = Semver.parse("1.2.3-beta.a") local res = Semver.parse("1.2.3-beta.a")
check.is_true(res:isErr()) check.is_true(res:isErr())
check.table.contains(res:unwrapErr(), { check.table.contains(res:unwrapErr(), {
kind = { kind = {
id = "InvalidPrereleaseOrdinalType", id = "InvalidPrereleaseOrdinalType",
expected = "number", expected = "number",
got = "char", got = "char",
}, },
}) })
-- Test with symbol ordinal -- Test with symbol ordinal
res = Semver.parse("1.2.3-beta.$") res = Semver.parse("1.2.3-beta.$")
check.is_true(res:isErr()) check.is_true(res:isErr())
check.table.contains(res:unwrapErr(), { check.table.contains(res:unwrapErr(), {
kind = { kind = {
id = "InvalidPrereleaseOrdinalType", id = "InvalidPrereleaseOrdinalType",
expected = "number", expected = "number",
got = "symbol", got = "symbol",
}, },
}) })
end) end)
end) end)
end end