forked from qt-creator/qt-creator
FilePath: Fix operator+ to use stringAppend instead of pathAppended
Change-Id: I643a2e9eed22fafc793bbc75cba0344c4005b3f3 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -969,7 +969,7 @@ bool FilePath::operator>=(const FilePath &other) const
|
|||||||
|
|
||||||
FilePath FilePath::operator+(const QString &s) const
|
FilePath FilePath::operator+(const QString &s) const
|
||||||
{
|
{
|
||||||
return pathAppended(s);
|
return stringAppended(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \returns whether FilePath is a child of \a s
|
/// \returns whether FilePath is a child of \a s
|
||||||
@@ -1277,9 +1277,7 @@ FilePath FilePath::pathAppended(const QString &path) const
|
|||||||
|
|
||||||
FilePath FilePath::stringAppended(const QString &str) const
|
FilePath FilePath::stringAppended(const QString &str) const
|
||||||
{
|
{
|
||||||
FilePath fn = *this;
|
return FilePath::fromString(toString() + str);
|
||||||
fn.m_path.append(str);
|
|
||||||
return fn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t FilePath::hash(uint seed) const
|
size_t FilePath::hash(uint seed) const
|
||||||
|
@@ -783,21 +783,29 @@ void tst_fileutils::onDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void tst_fileutils::plus_data() {
|
void tst_fileutils::plus_data() {
|
||||||
tst_fileutils::pathAppended_data();
|
QTest::addColumn<FilePath>("left");
|
||||||
|
QTest::addColumn<QString>("right");
|
||||||
|
QTest::addColumn<FilePath>("expected");
|
||||||
|
|
||||||
|
QTest::newRow("empty") << FilePath() << QString() << FilePath();
|
||||||
|
QTest::newRow("empty-left") << FilePath() << "a" << FilePath("a");
|
||||||
|
QTest::newRow("empty-right") << FilePath("a") << QString() << FilePath("a");
|
||||||
|
QTest::newRow("add-root") << FilePath() << QString("/") << FilePath("/");
|
||||||
|
QTest::newRow("add-root-and-more") << FilePath() << QString("/test/blah") << FilePath("/test/blah");
|
||||||
|
QTest::newRow("add-extension") << FilePath::fromString("/a") << QString(".txt") << FilePath("/a.txt");
|
||||||
|
QTest::newRow("trailing-slash") << FilePath::fromString("/a") << QString("b/") << FilePath("/ab/");
|
||||||
|
QTest::newRow("slash-trailing-slash") << FilePath::fromString("/a/") << QString("b/") << FilePath("/a/b/");
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_fileutils::plus()
|
void tst_fileutils::plus()
|
||||||
{
|
{
|
||||||
QFETCH(QString, left);
|
QFETCH(FilePath, left);
|
||||||
QFETCH(QString, right);
|
QFETCH(QString, right);
|
||||||
QFETCH(QString, expected);
|
QFETCH(FilePath, expected);
|
||||||
|
|
||||||
const FilePath fleft = FilePath::fromString(left);
|
const FilePath result = left + right;
|
||||||
const FilePath fexpected = FilePath::fromString(expected);
|
|
||||||
|
|
||||||
const FilePath result = fleft + right;
|
QCOMPARE(expected, result);
|
||||||
|
|
||||||
QCOMPARE(fexpected, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(tst_fileutils)
|
QTEST_GUILESS_MAIN(tst_fileutils)
|
||||||
|
Reference in New Issue
Block a user