File indexing completed on 2024-05-12 05:51:59
0001 /* This file is part of the KDE project 0002 * 0003 * SPDX-FileCopyrightText: 2018 Gregor Mi <codestruct@posteo.org> 0004 * SPDX-FileCopyrightText: 2019 Dominik Haumann <dhaumann@kde.org> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "tabswitchertest.h" 0010 #include "tabswitcherfilesmodel.h" 0011 0012 #include <QTest> 0013 0014 QTEST_MAIN(KateTabSwitcherTest) 0015 0016 void KateTabSwitcherTest::initTestCase() 0017 { 0018 } 0019 0020 void KateTabSwitcherTest::cleanupTestCase() 0021 { 0022 } 0023 0024 void KateTabSwitcherTest::testLongestCommonPrefix() 0025 { 0026 QFETCH(std::vector<QString>, input_strings); 0027 QFETCH(QString, expected); 0028 0029 QCOMPARE(detail::longestCommonPrefix(input_strings), expected); 0030 } 0031 0032 void KateTabSwitcherTest::testLongestCommonPrefix_data() 0033 { 0034 QTest::addColumn<std::vector<QString>>("input_strings"); 0035 QTest::addColumn<QString>("expected"); 0036 std::vector<QString> strs; 0037 0038 strs.clear(); 0039 strs.push_back(QStringLiteral("/home/user1/a")); 0040 strs.push_back(QStringLiteral("/home/user1/bc")); 0041 QTest::newRow("standard case") << strs << QStringLiteral("/home/user1/"); 0042 0043 strs.clear(); 0044 strs.push_back(QStringLiteral("/home/a")); 0045 strs.push_back(QStringLiteral("/home/b")); 0046 strs.push_back(QLatin1String("")); 0047 QTest::newRow("empty string at the end of the list") << strs << QString(); 0048 0049 strs.clear(); 0050 strs.push_back(QLatin1String("")); 0051 strs.push_back(QStringLiteral("/home/a")); 0052 strs.push_back(QStringLiteral("/home/b")); 0053 strs.push_back(QLatin1String("")); 0054 QTest::newRow("empty string not only at the end of the list") << strs << QString(); 0055 0056 strs.clear(); 0057 strs.push_back(QStringLiteral("/home/a")); 0058 strs.push_back(QStringLiteral("/etc/b")); 0059 QTest::newRow("a prefix with length 1") << strs << QStringLiteral("/"); 0060 0061 strs.clear(); 0062 strs.push_back(QStringLiteral("a")); 0063 strs.push_back(QStringLiteral("a")); 0064 QTest::newRow("two equal strings") << strs << QStringLiteral("a"); 0065 0066 strs.clear(); 0067 strs.push_back(QStringLiteral("/home/autolink")); 0068 strs.push_back(QStringLiteral("/home/async")); 0069 QTest::newRow("find correct path prefix") << strs << QStringLiteral("/home/"); 0070 0071 strs.clear(); 0072 QTest::newRow("empty list") << strs << QString(); 0073 0074 strs.clear(); 0075 strs.push_back(QStringLiteral("/home/a")); 0076 QTest::newRow("list with one item") << strs << QString(); 0077 } 0078 0079 #include "moc_tabswitchertest.cpp"