mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-07-08 13:08:29 +02:00
add modrinth pre-release support to flexVer implementation
extended the flexVer implementation to consider any space that is after a numeric section as a pre-release. Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
5a0931d3cf
commit
8427626e56
2 changed files with 33 additions and 5 deletions
|
|
@ -107,9 +107,11 @@ void Version::parse()
|
||||||
if (c == '+') {
|
if (c == '+') {
|
||||||
break; // Ignore appendices
|
break; // Ignore appendices
|
||||||
}
|
}
|
||||||
if (c == '-') {
|
// custom: the space is special to handle the strings like "1.20 Pre-Release 1"
|
||||||
|
// this is needed to support Modrinth versions
|
||||||
|
if (c == '-' || c == ' ') {
|
||||||
// Add dash to component
|
// Add dash to component
|
||||||
cur.value += '-';
|
cur.value += c;
|
||||||
i++;
|
i++;
|
||||||
// If the next rune is non-digit, mark as pre-release (requires >= 1 non-digit after dash so the component has length > 1)
|
// If the next rune is non-digit, mark as pre-release (requires >= 1 non-digit after dash so the component has length > 1)
|
||||||
if (i < len && !m_string.at(i).isDigit()) {
|
if (i < len && !m_string.at(i).isDigit()) {
|
||||||
|
|
@ -121,8 +123,9 @@ void Version::parse()
|
||||||
}
|
}
|
||||||
for (; i < len; i++) {
|
for (; i < len; i++) {
|
||||||
auto r = m_string.at(i);
|
auto r = m_string.at(i);
|
||||||
if ((r.isDigit() != (cur.t == Section::Type::Numeric)) ||
|
if ((r.isDigit() != (cur.t == Section::Type::Numeric)) // starts a new section
|
||||||
(r == '-' && cur.t != Section::Type::PreRelease) // "---" is a valid pre-release component
|
|| (r == ' ' && cur.t == Section::Type::Numeric) // custom: numeric section then a space is a pre-release
|
||||||
|
|| (r == '-' && cur.t != Section::Type::PreRelease) // "---" is a valid pre-release component
|
||||||
|| r == '+') {
|
|| r == '+') {
|
||||||
// Run completed (do not consume this rune)
|
// Run completed (do not consume this rune)
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -181,8 +181,33 @@ class VersionTest : public QObject {
|
||||||
QCOMPARE(v1 > v2, !lessThan && !equal);
|
QCOMPARE(v1 > v2, !lessThan && !equal);
|
||||||
QCOMPARE(v1 == v2, equal);
|
QCOMPARE(v1 == v2, equal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_strict_weak_order()
|
||||||
|
{
|
||||||
|
// this tests the strict_weak_order
|
||||||
|
// https://en.cppreference.com/w/cpp/concepts/strict_weak_order.html
|
||||||
|
Version a("1.10 Pre-Release 1"); // this is a pre-relese is before b because ' ' is lower than '-'
|
||||||
|
Version b("1.10-pre1"); // this is a pre-release is before c that is an actual release
|
||||||
|
Version c("1.10");
|
||||||
|
|
||||||
|
auto r = [](const Version& a, const Version& b) { return a < b; };
|
||||||
|
auto e = [&r](const Version& a, const Version& b) { return !r(a, b) && !r(b, a); };
|
||||||
|
|
||||||
|
qCritical() << a << b << c;
|
||||||
|
|
||||||
|
// irreflexive
|
||||||
|
QCOMPARE(r(a, a), false);
|
||||||
|
QCOMPARE(r(b, b), false);
|
||||||
|
QCOMPARE(r(c, c), false);
|
||||||
|
// transitive
|
||||||
|
QCOMPARE(r(a, b), true);
|
||||||
|
QCOMPARE(r(b, c), true);
|
||||||
|
QCOMPARE(r(a, c), true);
|
||||||
|
// transitive equivalence
|
||||||
|
QCOMPARE(e(a, b) && e(b, c), e(a, c));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(VersionTest)
|
QTEST_GUILESS_MAIN(VersionTest)
|
||||||
|
|
||||||
#include "Version_test.moc"
|
#include "Version_test.moc"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue