summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'SwifTools')
-rw-r--r--SwifTools/TabComplete.cpp5
-rw-r--r--SwifTools/UnitTest/TabCompleteTest.cpp141
2 files changed, 130 insertions, 16 deletions
diff --git a/SwifTools/TabComplete.cpp b/SwifTools/TabComplete.cpp
index 2fd0547..1e15595 100644
--- a/SwifTools/TabComplete.cpp
+++ b/SwifTools/TabComplete.cpp
@@ -13,9 +13,10 @@
namespace Swift {
void TabComplete::addWord(const String& word) {
- words_.push_back(word);
+ words_.erase(std::remove(words_.begin(), words_.end(), word), words_.end());
+ words_.insert(words_.begin(), word);
if (word.getLowerCase().beginsWith(lastShort_)) {
- lastCompletionCandidates_.push_back(word);
+ lastCompletionCandidates_.insert(lastCompletionCandidates_.begin(), word);
}
}
diff --git a/SwifTools/UnitTest/TabCompleteTest.cpp b/SwifTools/UnitTest/TabCompleteTest.cpp
index 4d152f6..b7b643f 100644
--- a/SwifTools/UnitTest/TabCompleteTest.cpp
+++ b/SwifTools/UnitTest/TabCompleteTest.cpp
@@ -20,6 +20,7 @@ class TabCompleteTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testChangeMatch);
CPPUNIT_TEST(testRemoveDuringComplete);
CPPUNIT_TEST(testAddDuringComplete);
+ CPPUNIT_TEST(testSwiftRoomSample);
CPPUNIT_TEST_SUITE_END();
public:
@@ -71,14 +72,14 @@ public:
completer_.addWord(long2);
completer_.addWord("Bleh");
CPPUNIT_ASSERT_EQUAL(
- long1,
- completer_.completeWord(short1));
- CPPUNIT_ASSERT_EQUAL(
long2,
- completer_.completeWord(long1));
+ completer_.completeWord(short1));
CPPUNIT_ASSERT_EQUAL(
long1,
completer_.completeWord(long2));
+ CPPUNIT_ASSERT_EQUAL(
+ long2,
+ completer_.completeWord(long1));
}
void testChangeMatch() {
@@ -113,15 +114,15 @@ public:
completer_.addWord(long2);
completer_.addWord("Bleh");
CPPUNIT_ASSERT_EQUAL(
- long1,
- completer_.completeWord(short1));
- completer_.removeWord(long1);
- CPPUNIT_ASSERT_EQUAL(
long2,
- completer_.completeWord(long1));
+ completer_.completeWord(short1));
+ completer_.removeWord(long2);
CPPUNIT_ASSERT_EQUAL(
- long2,
+ long1,
completer_.completeWord(long2));
+ CPPUNIT_ASSERT_EQUAL(
+ long1,
+ completer_.completeWord(long1));
}
void testAddDuringComplete() {
@@ -134,17 +135,129 @@ public:
completer_.addWord(long2);
completer_.addWord("Bleh");
CPPUNIT_ASSERT_EQUAL(
- long1,
+ long2,
completer_.completeWord(short1));
completer_.addWord(long3);
CPPUNIT_ASSERT_EQUAL(
- long2,
- completer_.completeWord(long1));
+ long1,
+ completer_.completeWord(long2));
CPPUNIT_ASSERT_EQUAL(
long3,
- completer_.completeWord(long2));
+ completer_.completeWord(long1));
+ }
+
+ void testSwiftRoomSample() {
+ String t("t");
+ String Anpan("Anpan");
+ String cdubouloz("cdubouloz");
+ String Tobias("Tobias");
+ String Zash("Zash");
+ String lastsky("lastsky");
+ String Steve("Steve Kille");
+ String Flo("Flo");
+ String Test("Test");
+ String test("test");
+ completer_.addWord(Anpan);
+ completer_.addWord(cdubouloz);
+ completer_.addWord(Tobias);
+ completer_.addWord(lastsky);
+ completer_.addWord(Steve);
+ completer_.addWord(Flo);
+ completer_.addWord(Zash);
+
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(t));
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(Tobias));
+
+ completer_.addWord(Test);
+
+ CPPUNIT_ASSERT_EQUAL(
+ Test,
+ completer_.completeWord(t));
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(Test));
+ CPPUNIT_ASSERT_EQUAL(
+ Test,
+ completer_.completeWord(Tobias));
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(Test));
+
+ completer_.addWord(Zash);
+ completer_.addWord(Zash);
+ completer_.addWord(Zash);
+ completer_.addWord(Zash);
+
+ completer_.removeWord(Test);
+
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(t));
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(Tobias));
+
+ completer_.addWord(test);
+
+ completer_.addWord(Zash);
+ completer_.addWord(Zash);
+ completer_.addWord(Zash);
+ completer_.addWord(Zash);
+
+
+ CPPUNIT_ASSERT_EQUAL(
+ test,
+ completer_.completeWord(t));
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(test));
+ CPPUNIT_ASSERT_EQUAL(
+ test,
+ completer_.completeWord(Tobias));
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(test));
+
+ completer_.removeWord(test);
+
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(t));
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(Tobias));
+
+ completer_.removeWord(Tobias);
+ CPPUNIT_ASSERT_EQUAL(
+ t,
+ completer_.completeWord(t));
+ CPPUNIT_ASSERT_EQUAL(
+ t,
+ completer_.completeWord(t));
+ CPPUNIT_ASSERT_EQUAL(
+ t,
+ completer_.completeWord(t));
+ CPPUNIT_ASSERT_EQUAL(
+ t,
+ completer_.completeWord(t));
+
+ completer_.addWord(Tobias);
+
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(t));
+ CPPUNIT_ASSERT_EQUAL(
+ Tobias,
+ completer_.completeWord(Tobias));
+
}
+
+
private:
TabComplete completer_;
};