mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-05 20:51:25 -07:00
parent
71af105a89
commit
41d7d672ce
5 changed files with 92 additions and 48 deletions
|
@ -47,7 +47,7 @@ private slots:
|
|||
{
|
||||
using BAViews = QList<QByteArrayView>;
|
||||
|
||||
const auto check = [](const QByteArrayView in, const QByteArrayView sep, const BAViews expected)
|
||||
const auto checkSkipEmptyParts = [](const QByteArrayView in, const QByteArrayView sep, const BAViews expected)
|
||||
{
|
||||
// verify it works
|
||||
QCOMPARE(Utils::ByteArray::splitToViews(in, sep), expected);
|
||||
|
@ -56,26 +56,56 @@ private slots:
|
|||
using Latin1Views = QList<QLatin1StringView>;
|
||||
|
||||
const Latin1Views reference = QLatin1StringView(in)
|
||||
.tokenize(QLatin1StringView(sep), Qt::SkipEmptyParts).toContainer();
|
||||
.tokenize(QLatin1StringView(sep), Qt::SkipEmptyParts).toContainer();
|
||||
Latin1Views expectedStrings;
|
||||
for (const auto &string : expected)
|
||||
expectedStrings.append(QLatin1StringView(string));
|
||||
QCOMPARE(reference, expectedStrings);
|
||||
};
|
||||
|
||||
check({}, {}, {});
|
||||
check({}, "/", {});
|
||||
check("/", "/", {});
|
||||
check("/a", "/", {"a"});
|
||||
check("/a/", "/", {"a"});
|
||||
check("/a/b", "/", (BAViews {"a", "b"}));
|
||||
check("/a/b/", "/", (BAViews {"a", "b"}));
|
||||
check("/a/b", "//", {"/a/b"});
|
||||
check("//a/b", "//", {"a/b"});
|
||||
check("//a//b", "//", (BAViews {"a", "b"}));
|
||||
check("//a//b/", "//", (BAViews {"a", "b/"}));
|
||||
check("//a//b//", "//", (BAViews {"a", "b"}));
|
||||
check("///a//b//", "//", (BAViews {"/a", "b"}));
|
||||
checkSkipEmptyParts({}, {}, {});
|
||||
checkSkipEmptyParts({}, "/", {});
|
||||
checkSkipEmptyParts("/", "/", {});
|
||||
checkSkipEmptyParts("/a", "/", {"a"});
|
||||
checkSkipEmptyParts("/a/", "/", {"a"});
|
||||
checkSkipEmptyParts("/a/b", "/", (BAViews {"a", "b"}));
|
||||
checkSkipEmptyParts("/a/b/", "/", (BAViews {"a", "b"}));
|
||||
checkSkipEmptyParts("/a/b", "//", {"/a/b"});
|
||||
checkSkipEmptyParts("//a/b", "//", {"a/b"});
|
||||
checkSkipEmptyParts("//a//b", "//", (BAViews {"a", "b"}));
|
||||
checkSkipEmptyParts("//a//b/", "//", (BAViews {"a", "b/"}));
|
||||
checkSkipEmptyParts("//a//b//", "//", (BAViews {"a", "b"}));
|
||||
checkSkipEmptyParts("///a//b//", "//", (BAViews {"/a", "b"}));
|
||||
|
||||
const auto checkKeepEmptyParts = [](const QByteArrayView in, const QByteArrayView sep, const BAViews expected)
|
||||
{
|
||||
// verify it works
|
||||
QCOMPARE(Utils::ByteArray::splitToViews(in, sep, Qt::KeepEmptyParts), expected);
|
||||
|
||||
// verify it has the same behavior as `split(Qt::KeepEmptyParts)`
|
||||
using Latin1Views = QList<QLatin1StringView>;
|
||||
|
||||
const Latin1Views reference = QLatin1StringView(in)
|
||||
.tokenize(QLatin1StringView(sep), Qt::KeepEmptyParts).toContainer();
|
||||
Latin1Views expectedStrings;
|
||||
for (const auto &string : expected)
|
||||
expectedStrings.append(QLatin1StringView(string));
|
||||
QCOMPARE(reference, expectedStrings);
|
||||
};
|
||||
|
||||
checkKeepEmptyParts({}, {}, {{}, {}});
|
||||
checkKeepEmptyParts({}, "/", {{}});
|
||||
checkKeepEmptyParts("/", "/", {"", ""});
|
||||
checkKeepEmptyParts("/a", "/", {"", "a"});
|
||||
checkKeepEmptyParts("/a/", "/", {"", "a", ""});
|
||||
checkKeepEmptyParts("/a/b", "/", (BAViews {"", "a", "b"}));
|
||||
checkKeepEmptyParts("/a/b/", "/", (BAViews {"", "a", "b", ""}));
|
||||
checkKeepEmptyParts("/a/b", "//", {"/a/b"});
|
||||
checkKeepEmptyParts("//a/b", "//", {"", "a/b"});
|
||||
checkKeepEmptyParts("//a//b", "//", (BAViews {"", "a", "b"}));
|
||||
checkKeepEmptyParts("//a//b/", "//", (BAViews {"", "a", "b/"}));
|
||||
checkKeepEmptyParts("//a//b//", "//", (BAViews {"", "a", "b", ""}));
|
||||
checkKeepEmptyParts("///a//b//", "//", (BAViews {"", "/a", "b", ""}));
|
||||
}
|
||||
|
||||
void testAsQByteArray() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue