feat(tests): add FlexVer test vector to the Version tests
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
0199d8a74f
commit
5ae69c079a
@ -17,15 +17,20 @@
|
||||
|
||||
#include <Version.h>
|
||||
|
||||
class ModUtilsTest : public QObject
|
||||
{
|
||||
class VersionTest : public QObject {
|
||||
Q_OBJECT
|
||||
void setupVersions()
|
||||
|
||||
void addDataColumns()
|
||||
{
|
||||
QTest::addColumn<QString>("first");
|
||||
QTest::addColumn<QString>("second");
|
||||
QTest::addColumn<bool>("lessThan");
|
||||
QTest::addColumn<bool>("equal");
|
||||
}
|
||||
|
||||
void setupVersions()
|
||||
{
|
||||
addDataColumns();
|
||||
|
||||
QTest::newRow("equal, explicit") << "1.2.0" << "1.2.0" << false << true;
|
||||
QTest::newRow("equal, implicit 1") << "1.2" << "1.2.0" << false << true;
|
||||
@ -50,19 +55,11 @@ class ModUtilsTest : public QObject
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
void cleanupTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_versionCompare_data()
|
||||
{
|
||||
setupVersions();
|
||||
}
|
||||
|
||||
void test_versionCompare()
|
||||
{
|
||||
QFETCH(QString, first);
|
||||
@ -79,8 +76,86 @@ private slots:
|
||||
QCOMPARE(v1 > v2, !lessThan && !equal);
|
||||
QCOMPARE(v1 == v2, equal);
|
||||
}
|
||||
|
||||
void test_flexVerTestVector_data()
|
||||
{
|
||||
addDataColumns();
|
||||
|
||||
QDir test_vector_dir(QFINDTESTDATA("testdata/Version"));
|
||||
|
||||
QFile vector_file{test_vector_dir.absoluteFilePath("test_vectors.txt")};
|
||||
|
||||
vector_file.open(QFile::OpenModeFlag::ReadOnly);
|
||||
|
||||
int test_number = 0;
|
||||
const QString test_name_template { "FlexVer test #%1 (%2)" };
|
||||
for (auto line = vector_file.readLine(); !vector_file.atEnd(); line = vector_file.readLine()) {
|
||||
line = line.simplified();
|
||||
if (line.startsWith('#') || line.isEmpty())
|
||||
continue;
|
||||
|
||||
test_number += 1;
|
||||
|
||||
auto split_line = line.split('<');
|
||||
if (split_line.size() == 2) {
|
||||
QString first{split_line.first().simplified()};
|
||||
QString second{split_line.last().simplified()};
|
||||
|
||||
auto new_test_name = test_name_template.arg(QString::number(test_number), "lessThan").toLatin1().data();
|
||||
QTest::newRow(new_test_name) << first << second << true << false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
split_line = line.split('=');
|
||||
if (split_line.size() == 2) {
|
||||
QString first{split_line.first().simplified()};
|
||||
QString second{split_line.last().simplified()};
|
||||
|
||||
auto new_test_name = test_name_template.arg(QString::number(test_number), "equals").toLatin1().data();
|
||||
QTest::newRow(new_test_name) << first << second << false << true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
split_line = line.split('>');
|
||||
if (split_line.size() == 2) {
|
||||
QString first{split_line.first().simplified()};
|
||||
QString second{split_line.last().simplified()};
|
||||
|
||||
auto new_test_name = test_name_template.arg(QString::number(test_number), "greaterThan").toLatin1().data();
|
||||
QTest::newRow(new_test_name) << first << second << false << false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
qCritical() << "Unexpected separator in the test vector: ";
|
||||
qCritical() << line;
|
||||
|
||||
QVERIFY(0 != 0);
|
||||
}
|
||||
|
||||
vector_file.close();
|
||||
}
|
||||
|
||||
void test_flexVerTestVector()
|
||||
{
|
||||
QFETCH(QString, first);
|
||||
QFETCH(QString, second);
|
||||
QFETCH(bool, lessThan);
|
||||
QFETCH(bool, equal);
|
||||
|
||||
const auto v1 = Version(first);
|
||||
const auto v2 = Version(second);
|
||||
|
||||
qDebug() << v1 << "vs" << v2;
|
||||
|
||||
QCOMPARE(v1 < v2, lessThan);
|
||||
QCOMPARE(v1 > v2, !lessThan && !equal);
|
||||
QCOMPARE(v1 == v2, equal);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(ModUtilsTest)
|
||||
QTEST_GUILESS_MAIN(VersionTest)
|
||||
|
||||
#include "Version_test.moc"
|
||||
|
63
tests/testdata/Version/test_vectors.txt
vendored
Normal file
63
tests/testdata/Version/test_vectors.txt
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
# Test vector from:
|
||||
# https://github.com/unascribed/FlexVer/blob/704e12759b6e59220ff888f8bf2ec15b8f8fd969/test/test_vectors.txt
|
||||
#
|
||||
# This test file is formatted as "<lefthand> <operator> <righthand>", seperated by the space character
|
||||
# Implementations should ignore lines starting with "#" and lines that have a length of 0
|
||||
|
||||
# Basic numeric ordering (lexical string sort fails these)
|
||||
10 > 2
|
||||
100 > 10
|
||||
|
||||
# Trivial common numerics
|
||||
1.0 < 1.1
|
||||
1.0 < 1.0.1
|
||||
1.1 > 1.0.1
|
||||
|
||||
# SemVer compatibility
|
||||
1.5 > 1.5-pre1
|
||||
1.5 = 1.5+foobar
|
||||
|
||||
# SemVer incompatibility
|
||||
1.5 < 1.5-2
|
||||
1.5-pre10 > 1.5-pre2
|
||||
|
||||
# Empty strings
|
||||
=
|
||||
1 >
|
||||
< 1
|
||||
|
||||
# Check boundary between textual and prerelease
|
||||
a-a < a
|
||||
|
||||
# Check boundary between textual and appendix
|
||||
a+a = a
|
||||
|
||||
# Dash is included in prerelease comparison (if stripped it will be a smaller component)
|
||||
# Note that a-a < a=a regardless since the prerelease splits the component creating a smaller first component; 0 is added to force splitting regardless
|
||||
a0-a < a0=a
|
||||
|
||||
# Pre-releases must contain only non-digit
|
||||
1.16.5-10 > 1.16.5
|
||||
|
||||
# Pre-releases can have multiple dashes (should not be split)
|
||||
# Reasoning for test data: "p-a!" > "p-a-" (correct); "p-a!" < "p-a t-" (what happens if every dash creates a new component)
|
||||
-a- > -a!
|
||||
|
||||
# Misc
|
||||
b1.7.3 > a1.2.6
|
||||
b1.2.6 > a1.7.3
|
||||
a1.1.2 < a1.1.2_01
|
||||
1.16.5-0.00.5 > 1.14.2-1.3.7
|
||||
1.0.0 < 1.0.0_01
|
||||
1.0.1 > 1.0.0_01
|
||||
1.0.0_01 < 1.0.1
|
||||
0.17.1-beta.1 < 0.17.1
|
||||
0.17.1-beta.1 < 0.17.1-beta.2
|
||||
1.4.5_01 = 1.4.5_01+fabric-1.17
|
||||
1.4.5_01 = 1.4.5_01+fabric-1.17+ohgod
|
||||
14w16a < 18w40b
|
||||
18w40a < 18w40b
|
||||
1.4.5_01+fabric-1.17 < 18w40b
|
||||
13w02a < c0.3.0_01
|
||||
0.6.0-1.18.x < 0.9.beta-1.18.x
|
||||
|
Loading…
Reference in New Issue
Block a user