mirror of
https://github.com/0x5eal/semver-luau.git
synced 2024-12-12 07:00:35 +00:00
chore(tests): migrate parse_invalid to use official frktest package
This commit is contained in:
parent
6e18053e5a
commit
b3db2f858c
1 changed files with 106 additions and 106 deletions
|
@ -1,122 +1,122 @@
|
|||
local frktest = require("../lune_packages/frktest").core
|
||||
local frktest = require("@pkg/frktest")
|
||||
local test = frktest.test
|
||||
local check = frktest.assert.check
|
||||
|
||||
local Semver = require("../lib")
|
||||
|
||||
return function()
|
||||
test.suite("Invalid semver parsing tests", function()
|
||||
test.case("Rejects missing components", function()
|
||||
local res = Semver.parse("1.2")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "MandatoryComponentMissing",
|
||||
components = { "1", "2" },
|
||||
},
|
||||
})
|
||||
end)
|
||||
test.suite("Invalid semver parsing tests", function()
|
||||
test.case("Rejects missing components", function()
|
||||
local res = Semver.parse("1.2")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "MandatoryComponentMissing",
|
||||
components = { "1", "2" },
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
||||
test.case("Rejects invalid component types", function()
|
||||
-- Test invalid major
|
||||
local res = Semver.parse("a.2.3")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidComponentType",
|
||||
component = "major",
|
||||
got = "char",
|
||||
},
|
||||
})
|
||||
test.case("Rejects invalid component types", function()
|
||||
-- Test invalid major
|
||||
local res = Semver.parse("a.2.3")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidComponentType",
|
||||
component = "major",
|
||||
got = "char",
|
||||
},
|
||||
})
|
||||
|
||||
-- Test invalid minor with symbols
|
||||
res = Semver.parse("1.$.3")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidComponentType",
|
||||
component = "minor",
|
||||
got = "symbol",
|
||||
},
|
||||
})
|
||||
-- Test invalid minor with symbols
|
||||
res = Semver.parse("1.$.3")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidComponentType",
|
||||
component = "minor",
|
||||
got = "symbol",
|
||||
},
|
||||
})
|
||||
|
||||
-- Test invalid patch
|
||||
res = Semver.parse("1.2.x")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidComponentType",
|
||||
component = "patch",
|
||||
got = "char",
|
||||
},
|
||||
})
|
||||
end)
|
||||
-- Test invalid patch
|
||||
res = Semver.parse("1.2.x")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidComponentType",
|
||||
component = "patch",
|
||||
got = "char",
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
||||
test.case("Rejects leading zeros", function()
|
||||
-- Test leading zeros in major
|
||||
local res = Semver.parse("01.2.3")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "LeadingZerosPresent",
|
||||
component = "major",
|
||||
},
|
||||
})
|
||||
test.case("Rejects leading zeros", function()
|
||||
-- Test leading zeros in major
|
||||
local res = Semver.parse("01.2.3")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "LeadingZerosPresent",
|
||||
component = "major",
|
||||
},
|
||||
})
|
||||
|
||||
-- Test leading zeros in minor
|
||||
res = Semver.parse("1.02.3")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "LeadingZerosPresent",
|
||||
component = "minor",
|
||||
},
|
||||
})
|
||||
-- Test leading zeros in minor
|
||||
res = Semver.parse("1.02.3")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "LeadingZerosPresent",
|
||||
component = "minor",
|
||||
},
|
||||
})
|
||||
|
||||
-- Test leading zeros in patch
|
||||
res = Semver.parse("1.2.03")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "LeadingZerosPresent",
|
||||
component = "patch",
|
||||
},
|
||||
})
|
||||
end)
|
||||
-- Test leading zeros in patch
|
||||
res = Semver.parse("1.2.03")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "LeadingZerosPresent",
|
||||
component = "patch",
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
||||
test.case("Rejects invalid prerelease types", function()
|
||||
local res = Semver.parse("1.2.3-gamma.1")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidPrereleaseType",
|
||||
type = "gamma",
|
||||
},
|
||||
})
|
||||
end)
|
||||
test.case("Rejects invalid prerelease types", function()
|
||||
local res = Semver.parse("1.2.3-gamma.1")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidPrereleaseType",
|
||||
type = "gamma",
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
||||
test.case("Rejects invalid prerelease ordinals", function()
|
||||
-- Test with character ordinal
|
||||
local res = Semver.parse("1.2.3-beta.a")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidPrereleaseOrdinalType",
|
||||
expected = "number",
|
||||
got = "char",
|
||||
},
|
||||
})
|
||||
test.case("Rejects invalid prerelease ordinals", function()
|
||||
-- Test with character ordinal
|
||||
local res = Semver.parse("1.2.3-beta.a")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidPrereleaseOrdinalType",
|
||||
expected = "number",
|
||||
got = "char",
|
||||
},
|
||||
})
|
||||
|
||||
-- Test with symbol ordinal
|
||||
res = Semver.parse("1.2.3-beta.$")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidPrereleaseOrdinalType",
|
||||
expected = "number",
|
||||
got = "symbol",
|
||||
},
|
||||
})
|
||||
end)
|
||||
end)
|
||||
-- Test with symbol ordinal
|
||||
res = Semver.parse("1.2.3-beta.$")
|
||||
check.is_true(res:isErr())
|
||||
check.table.contains(res:unwrapErr(), {
|
||||
kind = {
|
||||
id = "InvalidPrereleaseOrdinalType",
|
||||
expected = "number",
|
||||
got = "symbol",
|
||||
},
|
||||
})
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue