summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2014-09-14 20:53:35 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2014-09-14 20:56:47 -0700
commit76cfe0df6cad8fc7e3cb858580233a72474b79a9 (patch)
treed44cad0b361c5be307e9a4394972c5ffd967f7c6
parent8417e77d7b60c220f28ac25f2812ea79509dfd99 (diff)
Add more tests of choices
-rw-r--r--fzytest.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/fzytest.c b/fzytest.c
index 285975a..75ea3b7 100644
--- a/fzytest.c
+++ b/fzytest.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <string.h>
#include "match.h"
#include "choices.h"
@@ -22,6 +23,7 @@ int test_match(){
/* non-match */
assert(!has_match("a", ""));
assert(!has_match("a", "b"));
+ assert(!has_match("ass", "tags"));
/* match when query is empty */
assert(has_match("", ""));
@@ -111,7 +113,7 @@ int test_positions_exact(){
return 0;
}
-int test_empty_choices(){
+int test_choices_empty(){
choices_t choices;
choices_init(&choices);
assert(choices.size == 0);
@@ -128,6 +130,32 @@ int test_empty_choices(){
return 0;
}
+int test_choices_1(){
+ choices_t choices;
+ choices_init(&choices);
+ choices_add(&choices, "tags");
+
+ choices_search(&choices, "");
+ assert(choices.available == 1);
+ assert(choices.selection == 0);
+
+ choices_search(&choices, "t");
+ assert(choices.available == 1);
+ assert(choices.selection == 0);
+
+ choices_prev(&choices);
+ assert(choices.selection == 0);
+
+ choices_next(&choices);
+ assert(choices.selection == 0);
+
+ assert(!strcmp(choices_get(&choices, 0), "tags"));
+ assert(choices_get(&choices, 1) == NULL);
+
+ choices_free(&choices);
+ return 0;
+}
+
void summary(){
printf("%i tests, %i assertions, %i failures\n", testsrun, assertionsrun, testsfailed);
}
@@ -144,7 +172,8 @@ int main(int argc, char *argv[]){
runtest(test_positions_4);
runtest(test_positions_exact);
- runtest(test_empty_choices);
+ runtest(test_choices_empty);
+ runtest(test_choices_1);
summary();