summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarcus Tillmanns <marcus.tillmanns@qt.io>2023-05-10 08:53:35 +0200
committerMarcus Tillmanns <marcus.tillmanns@qt.io>2023-05-10 08:56:32 +0000
commitfc95d7a73730f67584891471d912dfd7f65a9cc2 (patch)
treed785884ccea11b7320457f06034b474d4f78a6c4 /tests
parent2c433f7fe1b47b3fd497f87e51e248c70323a3f5 (diff)
downloadqt-creator-fc95d7a73730f67584891471d912dfd7f65a9cc2.tar.gz
Utils: Improve FilePath::sort
Remove the conversion to/from QString for sorting. Change-Id: I89921328b6d9e952c802d41998495bd2ffbb9f99 Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/utils/filepath/tst_filepath.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/utils/filepath/tst_filepath.cpp b/tests/auto/utils/filepath/tst_filepath.cpp
index 64888937de..6e11ddb71c 100644
--- a/tests/auto/utils/filepath/tst_filepath.cpp
+++ b/tests/auto/utils/filepath/tst_filepath.cpp
@@ -4,6 +4,7 @@
#include <QRandomGenerator>
#include <QtTest>
+#include <utils/algorithm.h>
#include <utils/filepath.h>
#include <utils/hostosinfo.h>
#include <utils/link.h>
@@ -109,6 +110,9 @@ private slots:
void searchInWithFilter();
+ void sort();
+ void sort_data();
+
private:
QTemporaryDir tempDir;
QString rootPath;
@@ -1657,6 +1661,54 @@ void tst_filepath::tmp()
}
}
+void tst_filepath::sort()
+{
+ QFETCH(QStringList, input);
+
+ FilePaths filePaths = Utils::transform(input, &FilePath::fromString);
+ QStringList sorted = input;
+ sorted.sort();
+
+ FilePath::sort(filePaths);
+ QStringList sortedPaths = Utils::transform(filePaths, &FilePath::toString);
+
+ QCOMPARE(sortedPaths, sorted);
+}
+
+void tst_filepath::sort_data()
+{
+ QTest::addColumn<QStringList>("input");
+
+ QTest::addRow("empty") << QStringList{};
+
+ QTest::addRow("one") << QStringList{"foo"};
+ QTest::addRow("two") << QStringList{"foo", "bar"};
+ QTest::addRow("three") << QStringList{"foo", "bar", "baz"};
+
+ QTest::addRow("one-absolute") << QStringList{"/foo"};
+ QTest::addRow("two-absolute") << QStringList{"/foo", "/bar"};
+
+ QTest::addRow("one-relative") << QStringList{"foo"};
+
+ QTest::addRow("one-absolute-one-relative") << QStringList{"/foo", "bar"};
+
+ QTest::addRow("host") << QStringList{"ssh://test/blah", "ssh://gulp/blah", "ssh://zzz/blah"};
+
+ QTest::addRow("scheme") << QStringList{"ssh://test/blah",
+ "ssh://gulp/blah",
+ "ssh://zzz/blah",
+ "aaa://gulp/blah",
+ "xyz://test/blah"};
+
+ QTest::addRow("others") << QStringList{"a://a//a",
+ "a://b//a",
+ "a://a//b",
+ "a://b//b",
+ "b://b//b"};
+ QTest::addRow("others-reversed")
+ << QStringList{"b://b//b", "a://b//b", "a://a//b", "a://b//a", "a://a//a"};
+}
+
QTEST_GUILESS_MAIN(tst_filepath)
#include "tst_filepath.moc"