Changeset View
Changeset View
Standalone View
Standalone View
addons/tabswitcher/autotests/tabswitchertest.cpp
Show All 29 Lines | |||||
30 | } | 30 | } | ||
31 | 31 | | |||
32 | void KateTabSwitcherTest::cleanupTestCase() | 32 | void KateTabSwitcherTest::cleanupTestCase() | ||
33 | { | 33 | { | ||
34 | } | 34 | } | ||
35 | 35 | | |||
36 | void KateTabSwitcherTest::testLongestCommonPrefix() | 36 | void KateTabSwitcherTest::testLongestCommonPrefix() | ||
37 | { | 37 | { | ||
38 | // standard case | 38 | QFETCH(std::vector<QString>, input_strings); | ||
39 | QFETCH(QString, expected); | ||||
40 | | ||||
41 | QCOMPARE(detail::longestCommonPrefix(input_strings), expected); | ||||
42 | } | ||||
43 | | ||||
44 | void KateTabSwitcherTest::testLongestCommonPrefix_data() | ||||
45 | { | ||||
46 | QTest::addColumn<std::vector<QString>>("input_strings"); | ||||
47 | QTest::addColumn<QString>("expected"); | ||||
39 | std::vector<QString> strs; | 48 | std::vector<QString> strs; | ||
49 | | ||||
50 | strs.clear(); | ||||
40 | strs.push_back(QLatin1String("/home/user1/a")); | 51 | strs.push_back(QLatin1String("/home/user1/a")); | ||
41 | strs.push_back(QLatin1String("/home/user1/bc")); | 52 | strs.push_back(QLatin1String("/home/user1/bc")); | ||
42 | QCOMPARE(detail::longestCommonPrefix(strs), QLatin1String("/home/user1/")); | 53 | QTest::newRow("standard case") << strs << QString(QLatin1String("/home/user1/")); | ||
43 | 54 | | |||
44 | // empty string at the end of the list | | |||
45 | strs.clear(); | 55 | strs.clear(); | ||
46 | strs.push_back(QLatin1String("/home/a")); | 56 | strs.push_back(QLatin1String("/home/a")); | ||
47 | strs.push_back(QLatin1String("/home/b")); | 57 | strs.push_back(QLatin1String("/home/b")); | ||
48 | strs.push_back(QLatin1String("")); | 58 | strs.push_back(QLatin1String("")); | ||
49 | QCOMPARE(detail::longestCommonPrefix(strs), QLatin1String("")); | 59 | QTest::newRow("empty string at the end of the list") << strs << QString(); | ||
50 | 60 | | |||
51 | // empty string not only at the end of the list | | |||
52 | strs.clear(); | 61 | strs.clear(); | ||
53 | strs.push_back(QLatin1String("")); | 62 | strs.push_back(QLatin1String("")); | ||
54 | strs.push_back(QLatin1String("/home/a")); | 63 | strs.push_back(QLatin1String("/home/a")); | ||
55 | strs.push_back(QLatin1String("/home/b")); | 64 | strs.push_back(QLatin1String("/home/b")); | ||
56 | strs.push_back(QLatin1String("")); | 65 | strs.push_back(QLatin1String("")); | ||
57 | QCOMPARE(detail::longestCommonPrefix(strs), QLatin1String("")); | 66 | QTest::newRow("empty string not only at the end of the list") << strs << QString(); | ||
58 | 67 | | |||
59 | // a prefix with length 1 | | |||
60 | strs.clear(); | 68 | strs.clear(); | ||
61 | strs.push_back(QLatin1String("/home/a")); | 69 | strs.push_back(QLatin1String("/home/a")); | ||
62 | strs.push_back(QLatin1String("/etc/b")); | 70 | strs.push_back(QLatin1String("/etc/b")); | ||
63 | QCOMPARE(detail::longestCommonPrefix(strs), QLatin1String("/")); | 71 | QTest::newRow("a prefix with length 1") << strs << QString(QLatin1String("/")); | ||
72 | | ||||
73 | strs.clear(); | ||||
74 | strs.push_back(QLatin1String("a")); | ||||
75 | strs.push_back(QLatin1String("a")); | ||||
76 | QTest::newRow("two equal strings") << strs << QString(QLatin1String("a")); | ||||
64 | } | 77 | } |