summaryrefslogtreecommitdiffstats
blob: 4d152f613454fba8ed480fd9e08b897d0b4e1038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * Copyright (c) 2010 Kevin Smith
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#include "SwifTools/TabComplete.h"

using namespace Swift;

class TabCompleteTest : public CppUnit::TestFixture {
	CPPUNIT_TEST_SUITE(TabCompleteTest);
	CPPUNIT_TEST(testEmpty);
	CPPUNIT_TEST(testNoMatch);
	CPPUNIT_TEST(testOneMatch);
	CPPUNIT_TEST(testTwoMatch);
	CPPUNIT_TEST(testChangeMatch);
	CPPUNIT_TEST(testRemoveDuringComplete);
	CPPUNIT_TEST(testAddDuringComplete);
	CPPUNIT_TEST_SUITE_END();
	
public:
	TabCompleteTest() {};
	
	void setUp() {
		completer_ = TabComplete();
	}
	
	void testEmpty() {
		String blah("Blah");
		CPPUNIT_ASSERT_EQUAL(
			blah,
			completer_.completeWord(blah));
		CPPUNIT_ASSERT_EQUAL(
			blah,
			completer_.completeWord(blah));
	}

	void testNoMatch() {
		completer_.addWord("Bleh");
		String blah("Blah");
		CPPUNIT_ASSERT_EQUAL(
			blah,
			completer_.completeWord(blah));
		CPPUNIT_ASSERT_EQUAL(
			blah,
			completer_.completeWord(blah));
	}

	void testOneMatch() {
		String short1("Bl");
		String long1("Blehling");
		completer_.addWord(long1);
		CPPUNIT_ASSERT_EQUAL(
			long1,
			completer_.completeWord(short1));
		CPPUNIT_ASSERT_EQUAL(
			long1,
			completer_.completeWord(long1));
	}
	
	void testTwoMatch() {
		String short1("Hur");
		String long1("Hurgle");
		String long2("Hurdler");
		completer_.addWord(long1);
		completer_.addWord("Blah");
		completer_.addWord(long2);
		completer_.addWord("Bleh");
		CPPUNIT_ASSERT_EQUAL(
			long1,
			completer_.completeWord(short1));
		CPPUNIT_ASSERT_EQUAL(
			long2,
			completer_.completeWord(long1));
		CPPUNIT_ASSERT_EQUAL(
			long1,
			completer_.completeWord(long2));
	}

	void testChangeMatch() {
		String short1("Hur");
		String short2("Rub");
		String long1("Hurgle");
		String long2("Rubbish");
		completer_.addWord(long2);
		completer_.addWord("Blah");
		completer_.addWord(long1);
		completer_.addWord("Bleh");
		CPPUNIT_ASSERT_EQUAL(
			long1,
			completer_.completeWord(short1));
		CPPUNIT_ASSERT_EQUAL(
			long2,
			completer_.completeWord(short2));
		CPPUNIT_ASSERT_EQUAL(
			long2,
			completer_.completeWord(long2));
		CPPUNIT_ASSERT_EQUAL(
			long1,
			completer_.completeWord(short1));
	}

	void testRemoveDuringComplete() {
		String short1("Kev");
		String long1("Kevin");
		String long2("Kevlar");
		completer_.addWord(long1);
		completer_.addWord("Blah");
		completer_.addWord(long2);
		completer_.addWord("Bleh");
		CPPUNIT_ASSERT_EQUAL(
			long1,
			completer_.completeWord(short1));
		completer_.removeWord(long1);
		CPPUNIT_ASSERT_EQUAL(
			long2,
			completer_.completeWord(long1));
		CPPUNIT_ASSERT_EQUAL(
			long2,
			completer_.completeWord(long2));
	}

	void testAddDuringComplete() {
		String short1("Rem");
		String long1("Remko");
		String long2("Remove");
		String long3("Remedial");
		completer_.addWord(long1);
		completer_.addWord("Blah");
		completer_.addWord(long2);
		completer_.addWord("Bleh");
		CPPUNIT_ASSERT_EQUAL(
			long1,
			completer_.completeWord(short1));
		completer_.addWord(long3);
		CPPUNIT_ASSERT_EQUAL(
			long2,
			completer_.completeWord(long1));
		CPPUNIT_ASSERT_EQUAL(
			long3,
			completer_.completeWord(long2));
	}

private:
	TabComplete completer_;
};

CPPUNIT_TEST_SUITE_REGISTRATION(TabCompleteTest);