File indexing completed on 2024-05-19 16:19:08
0001 /*************************************************************************** 0002 Copyright (C) 2020 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #include "completiontest.h" 0026 0027 #include "../fieldcompletion.h" 0028 #include "../field.h" 0029 0030 #include <QTest> 0031 0032 QTEST_APPLESS_MAIN( CompletionTest ) 0033 0034 void CompletionTest::testBasic() { 0035 Tellico::FieldCompletion cmp(false); // not mutiple 0036 cmp.addItem(QStringLiteral("Atlas V")); 0037 cmp.addItem(QStringLiteral("Falcon 9")); 0038 cmp.addItem(QStringLiteral("New Shephard")); 0039 cmp.addItem(QStringLiteral("New Glenn")); 0040 0041 QString result = cmp.makeCompletion(QStringLiteral("Fal")); 0042 QCOMPARE(result, QStringLiteral("Falcon 9")); 0043 } 0044 0045 void CompletionTest::testMultiple() { 0046 Tellico::FieldCompletion cmp(true); // mutiple 0047 cmp.addItem(QStringLiteral("Atlas V")); 0048 cmp.addItem(QStringLiteral("Falcon 9")); 0049 cmp.addItem(QStringLiteral("New Shephard")); 0050 cmp.addItem(QStringLiteral("New Glenn")); 0051 cmp.addItem(QStringLiteral("Vulcan")); 0052 cmp.addItem(QStringLiteral("Starship")); 0053 0054 QString result = cmp.makeCompletion(QStringLiteral("Fal")); 0055 QCOMPARE(result, QStringLiteral("Falcon 9")); 0056 result = cmp.makeCompletion(QStringLiteral("Atlas V; Fal")); 0057 QCOMPARE(result, QStringLiteral("Atlas V; Falcon 9")); 0058 QVERIFY(!cmp.hasMultipleMatches()); 0059 result = cmp.makeCompletion(QStringLiteral("Atlas V; New")); 0060 // matches first inserted 0061 QCOMPARE(result, QStringLiteral("Atlas V; New Shephard")); 0062 QVERIFY(cmp.hasMultipleMatches()); 0063 QStringList allMatches = cmp.allMatches(); 0064 QCOMPARE(allMatches.count(), 2); 0065 QVERIFY(allMatches.contains(QStringLiteral("Atlas V; New Shephard"))); 0066 QVERIFY(allMatches.contains(QStringLiteral("Atlas V; New Glenn"))); 0067 0068 // complete on third item 0069 result = cmp.makeCompletion(QStringLiteral("Atlas V; Falcon 9; S")); 0070 QCOMPARE(result, QStringLiteral("Atlas V; Falcon 9; Starship")); 0071 0072 // now back to a single match 0073 result = cmp.makeCompletion(QStringLiteral("Atl")); 0074 QCOMPARE(result, QStringLiteral("Atlas V")); 0075 }