feat(data,text,testing): implement VL-002 TOML, VL-008 StrictJson UTF-8, VL-009 native tests, and VL-013 Semver shorthands
This commit is contained in:
1 parent
53d42bda42
commit
adfc8548dc
11 files changed
+2888
-28
No files matched your search
@@ -438,6 +438,54 @@ namespace Void::Semver
|
||||
using Clause = std::vector<Comparator>;
|
||||
std::vector<Clause> m_alternatives;
|
||||
|
||||
struct PartialVersion {
|
||||
Version version{};
|
||||
int components{0};
|
||||
};
|
||||
|
||||
[[nodiscard]] static std::optional<PartialVersion>
|
||||
parse_partial(std::string_view token)
|
||||
{
|
||||
if (token.empty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
if (token.find('-') != std::string_view::npos ||
|
||||
token.find('+') != std::string_view::npos) {
|
||||
const auto full = parse_strict(token);
|
||||
if (!full) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return PartialVersion{*full, 3};
|
||||
}
|
||||
const auto first_dot = token.find('.');
|
||||
if (first_dot == std::string_view::npos) {
|
||||
unsigned major = 0;
|
||||
if (!Detail::parse_component(token, major)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return PartialVersion{
|
||||
Version{.major = major, .minor = 0, .patch = 0}, 1};
|
||||
}
|
||||
const auto second_dot = token.find('.', first_dot + 1);
|
||||
if (second_dot == std::string_view::npos) {
|
||||
unsigned major = 0;
|
||||
unsigned minor = 0;
|
||||
if (!Detail::parse_component(token.substr(0, first_dot),
|
||||
major) ||
|
||||
!Detail::parse_component(token.substr(first_dot + 1),
|
||||
minor)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return PartialVersion{
|
||||
Version{.major = major, .minor = minor, .patch = 0}, 2};
|
||||
}
|
||||
const auto full = parse_strict(token);
|
||||
if (!full) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return PartialVersion{*full, 3};
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool append_token(Clause& clause,
|
||||
std::string_view token)
|
||||
{
|
||||
@@ -447,53 +495,76 @@ namespace Void::Semver
|
||||
if (token.starts_with('^') || token.starts_with('~')) {
|
||||
const char kind = token.front();
|
||||
token.remove_prefix(1);
|
||||
const auto lower = parse_strict(token);
|
||||
if (!lower) {
|
||||
const auto partial = parse_partial(token);
|
||||
if (!partial) {
|
||||
return false;
|
||||
}
|
||||
const Version& lower = partial->version;
|
||||
Version upper;
|
||||
if (kind == '~') {
|
||||
if (lower->minor ==
|
||||
if (partial->components == 1) {
|
||||
if (lower.major ==
|
||||
std::numeric_limits<unsigned>::max()) {
|
||||
return false;
|
||||
}
|
||||
upper = Version{.major = lower.major + 1,
|
||||
.minor = 0,
|
||||
.patch = 0,
|
||||
.pre_release = {},
|
||||
.build = {}};
|
||||
} else {
|
||||
if (lower.minor ==
|
||||
std::numeric_limits<unsigned>::max()) {
|
||||
return false;
|
||||
}
|
||||
upper = Version{.major = lower.major,
|
||||
.minor = lower.minor + 1,
|
||||
.patch = 0,
|
||||
.pre_release = {},
|
||||
.build = {}};
|
||||
}
|
||||
} else if (partial->components == 1) {
|
||||
if (lower.major ==
|
||||
std::numeric_limits<unsigned>::max()) {
|
||||
return false;
|
||||
}
|
||||
upper = Version{.major = lower->major,
|
||||
.minor = lower->minor + 1,
|
||||
.patch = 0,
|
||||
.pre_release = {},
|
||||
.build = {}};
|
||||
} else if (lower->major > 0) {
|
||||
if (lower->major ==
|
||||
std::numeric_limits<unsigned>::max()) {
|
||||
return false;
|
||||
}
|
||||
upper = Version{.major = lower->major + 1,
|
||||
upper = Version{.major = lower.major + 1,
|
||||
.minor = 0,
|
||||
.patch = 0,
|
||||
.pre_release = {},
|
||||
.build = {}};
|
||||
} else if (lower->minor > 0) {
|
||||
if (lower->minor ==
|
||||
} else if (lower.major > 0) {
|
||||
if (lower.major ==
|
||||
std::numeric_limits<unsigned>::max()) {
|
||||
return false;
|
||||
}
|
||||
upper = Version{.major = lower.major + 1,
|
||||
.minor = 0,
|
||||
.patch = 0,
|
||||
.pre_release = {},
|
||||
.build = {}};
|
||||
} else if (lower.minor > 0) {
|
||||
if (lower.minor ==
|
||||
std::numeric_limits<unsigned>::max()) {
|
||||
return false;
|
||||
}
|
||||
upper = Version{.major = 0,
|
||||
.minor = lower->minor + 1,
|
||||
.minor = lower.minor + 1,
|
||||
.patch = 0,
|
||||
.pre_release = {},
|
||||
.build = {}};
|
||||
} else {
|
||||
if (lower->patch ==
|
||||
if (lower.patch ==
|
||||
std::numeric_limits<unsigned>::max()) {
|
||||
return false;
|
||||
}
|
||||
upper = Version{.major = 0,
|
||||
.minor = 0,
|
||||
.patch = lower->patch + 1,
|
||||
.patch = lower.patch + 1,
|
||||
.pre_release = {},
|
||||
.build = {}};
|
||||
}
|
||||
clause.push_back({Operation::GreaterEqual, *lower});
|
||||
clause.push_back({Operation::GreaterEqual, lower});
|
||||
clause.push_back({Operation::Less, std::move(upper)});
|
||||
return true;
|
||||
}
|
||||
@@ -518,11 +589,11 @@ namespace Void::Semver
|
||||
} else if (token.starts_with('=')) {
|
||||
token.remove_prefix(1);
|
||||
}
|
||||
const auto version = parse_strict(token);
|
||||
if (!version) {
|
||||
const auto partial = parse_partial(token);
|
||||
if (!partial) {
|
||||
return false;
|
||||
}
|
||||
clause.push_back({operation, *version});
|
||||
clause.push_back({operation, partial->version});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user