Browse code

Add more tests of choices

John Hawthorn authored on 15/09/2014 03:53:35
Showing 1 changed files

... ...
@@ -1,4 +1,5 @@
1 1
 #include <stdio.h>
2
+#include <string.h>
2 3
 
3 4
 #include "match.h"
4 5
 #include "choices.h"
... ...
@@ -22,6 +23,7 @@ int test_match(){
22 23
 	/* non-match */
23 24
 	assert(!has_match("a", ""));
24 25
 	assert(!has_match("a", "b"));
26
+	assert(!has_match("ass", "tags"));
25 27
 
26 28
 	/* match when query is empty */
27 29
 	assert(has_match("", ""));
... ...
@@ -111,7 +113,7 @@ int test_positions_exact(){
111 113
 	return 0;
112 114
 }
113 115
 
114
-int test_empty_choices(){
116
+int test_choices_empty(){
115 117
 	choices_t choices;
116 118
 	choices_init(&choices);
117 119
 	assert(choices.size == 0);
... ...
@@ -128,6 +130,32 @@ int test_empty_choices(){
128 130
 	return 0;
129 131
 }
130 132
 
133
+int test_choices_1(){
134
+	choices_t choices;
135
+	choices_init(&choices);
136
+	choices_add(&choices, "tags");
137
+
138
+	choices_search(&choices, "");
139
+	assert(choices.available == 1);
140
+	assert(choices.selection == 0);
141
+
142
+	choices_search(&choices, "t");
143
+	assert(choices.available == 1);
144
+	assert(choices.selection == 0);
145
+
146
+	choices_prev(&choices);
147
+	assert(choices.selection == 0);
148
+
149
+	choices_next(&choices);
150
+	assert(choices.selection == 0);
151
+
152
+	assert(!strcmp(choices_get(&choices, 0), "tags"));
153
+	assert(choices_get(&choices, 1) == NULL);
154
+
155
+	choices_free(&choices);
156
+	return 0;
157
+}
158
+
131 159
 void summary(){
132 160
 	printf("%i tests, %i assertions, %i failures\n", testsrun, assertionsrun, testsfailed);
133 161
 }
... ...
@@ -144,7 +172,8 @@ int main(int argc, char *argv[]){
144 172
 	runtest(test_positions_4);
145 173
 	runtest(test_positions_exact);
146 174
 
147
-	runtest(test_empty_choices);
175
+	runtest(test_choices_empty);
176
+	runtest(test_choices_1);
148 177
 
149 178
 	summary();
150 179