| ... | ... |
@@ -8,7 +8,7 @@ |
| 8 | 8 |
|
| 9 | 9 |
#include "greatest/greatest.h" |
| 10 | 10 |
|
| 11 |
-#define ASSERT_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%d") |
|
| 11 |
+#define ASSERT_INT_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%d") |
|
| 12 | 12 |
|
| 13 | 13 |
static options_t default_options; |
| 14 | 14 |
static choices_t choices; |
| ... | ... |
@@ -26,15 +26,15 @@ static void teardown(void *udata) {
|
| 26 | 26 |
} |
| 27 | 27 |
|
| 28 | 28 |
TEST test_choices_empty() {
|
| 29 |
- ASSERT_EQ(0, choices.size); |
|
| 30 |
- ASSERT_EQ(0, choices.available); |
|
| 31 |
- ASSERT_EQ(0, choices.selection); |
|
| 29 |
+ ASSERT_INT_EQ(0, choices.size); |
|
| 30 |
+ ASSERT_INT_EQ(0, choices.available); |
|
| 31 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 32 | 32 |
|
| 33 | 33 |
choices_prev(&choices); |
| 34 |
- ASSERT_EQ(0, choices.selection); |
|
| 34 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 35 | 35 |
|
| 36 | 36 |
choices_next(&choices); |
| 37 |
- ASSERT_EQ(0, choices.selection); |
|
| 37 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 38 | 38 |
|
| 39 | 39 |
PASS(); |
| 40 | 40 |
} |
| ... | ... |
@@ -43,21 +43,21 @@ TEST test_choices_1() {
|
| 43 | 43 |
choices_add(&choices, "tags"); |
| 44 | 44 |
|
| 45 | 45 |
choices_search(&choices, ""); |
| 46 |
- ASSERT_EQ(1, choices.available); |
|
| 47 |
- ASSERT_EQ(0, choices.selection); |
|
| 46 |
+ ASSERT_INT_EQ(1, choices.available); |
|
| 47 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 48 | 48 |
|
| 49 | 49 |
choices_search(&choices, "t"); |
| 50 |
- ASSERT_EQ(1, choices.available); |
|
| 51 |
- ASSERT_EQ(0, choices.selection); |
|
| 50 |
+ ASSERT_INT_EQ(1, choices.available); |
|
| 51 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 52 | 52 |
|
| 53 | 53 |
choices_prev(&choices); |
| 54 |
- ASSERT_EQ(0, choices.selection); |
|
| 54 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 55 | 55 |
|
| 56 | 56 |
choices_next(&choices); |
| 57 |
- ASSERT_EQ(0, choices.selection); |
|
| 57 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 58 | 58 |
|
| 59 | 59 |
ASSERT(!strcmp(choices_get(&choices, 0), "tags")); |
| 60 |
- ASSERT_EQ(NULL, choices_get(&choices, 1)); |
|
| 60 |
+ ASSERT_INT_EQ(NULL, choices_get(&choices, 1)); |
|
| 61 | 61 |
|
| 62 | 62 |
PASS(); |
| 63 | 63 |
} |
| ... | ... |
@@ -68,40 +68,40 @@ TEST test_choices_2() {
|
| 68 | 68 |
|
| 69 | 69 |
/* Empty search */ |
| 70 | 70 |
choices_search(&choices, ""); |
| 71 |
- ASSERT_EQ(0, choices.selection); |
|
| 72 |
- ASSERT_EQ(2, choices.available); |
|
| 71 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 72 |
+ ASSERT_INT_EQ(2, choices.available); |
|
| 73 | 73 |
|
| 74 | 74 |
choices_next(&choices); |
| 75 |
- ASSERT_EQ(1, choices.selection); |
|
| 75 |
+ ASSERT_INT_EQ(1, choices.selection); |
|
| 76 | 76 |
choices_next(&choices); |
| 77 |
- ASSERT_EQ(0, choices.selection); |
|
| 77 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 78 | 78 |
|
| 79 | 79 |
choices_prev(&choices); |
| 80 |
- ASSERT_EQ(1, choices.selection); |
|
| 80 |
+ ASSERT_INT_EQ(1, choices.selection); |
|
| 81 | 81 |
choices_prev(&choices); |
| 82 |
- ASSERT_EQ(0, choices.selection); |
|
| 82 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 83 | 83 |
|
| 84 | 84 |
/* Filtered search */ |
| 85 | 85 |
choices_search(&choices, "te"); |
| 86 |
- ASSERT_EQ(1, choices.available); |
|
| 87 |
- ASSERT_EQ(0, choices.selection); |
|
| 86 |
+ ASSERT_INT_EQ(1, choices.available); |
|
| 87 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 88 | 88 |
ASSERT_STR_EQ("test", choices_get(&choices, 0));
|
| 89 | 89 |
|
| 90 | 90 |
choices_next(&choices); |
| 91 |
- ASSERT_EQ(0, choices.selection); |
|
| 91 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 92 | 92 |
|
| 93 | 93 |
choices_prev(&choices); |
| 94 |
- ASSERT_EQ(0, choices.selection); |
|
| 94 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 95 | 95 |
|
| 96 | 96 |
/* No results */ |
| 97 | 97 |
choices_search(&choices, "foobar"); |
| 98 |
- ASSERT_EQ(0, choices.available); |
|
| 99 |
- ASSERT_EQ(0, choices.selection); |
|
| 98 |
+ ASSERT_INT_EQ(0, choices.available); |
|
| 99 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 100 | 100 |
|
| 101 | 101 |
/* Different order due to scoring */ |
| 102 | 102 |
choices_search(&choices, "ts"); |
| 103 |
- ASSERT_EQ(2, choices.available); |
|
| 104 |
- ASSERT_EQ(0, choices.selection); |
|
| 103 |
+ ASSERT_INT_EQ(2, choices.available); |
|
| 104 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 105 | 105 |
ASSERT_STR_EQ("test", choices_get(&choices, 0));
|
| 106 | 106 |
ASSERT_STR_EQ("tags", choices_get(&choices, 1));
|
| 107 | 107 |
|
| ... | ... |
@@ -111,17 +111,17 @@ TEST test_choices_2() {
|
| 111 | 111 |
TEST test_choices_without_search() {
|
| 112 | 112 |
/* Before a search is run, it should return no results */ |
| 113 | 113 |
|
| 114 |
- ASSERT_EQ(0, choices.available); |
|
| 115 |
- ASSERT_EQ(0, choices.selection); |
|
| 116 |
- ASSERT_EQ(0, choices.size); |
|
| 117 |
- ASSERT_EQ(NULL, choices_get(&choices, 0)); |
|
| 114 |
+ ASSERT_INT_EQ(0, choices.available); |
|
| 115 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 116 |
+ ASSERT_INT_EQ(0, choices.size); |
|
| 117 |
+ ASSERT_INT_EQ(NULL, choices_get(&choices, 0)); |
|
| 118 | 118 |
|
| 119 | 119 |
choices_add(&choices, "test"); |
| 120 | 120 |
|
| 121 |
- ASSERT_EQ(0, choices.available); |
|
| 122 |
- ASSERT_EQ(0, choices.selection); |
|
| 123 |
- ASSERT_EQ(1, choices.size); |
|
| 124 |
- ASSERT_EQ(NULL, choices_get(&choices, 0)); |
|
| 121 |
+ ASSERT_INT_EQ(0, choices.available); |
|
| 122 |
+ ASSERT_INT_EQ(0, choices.selection); |
|
| 123 |
+ ASSERT_INT_EQ(1, choices.size); |
|
| 124 |
+ ASSERT_INT_EQ(NULL, choices_get(&choices, 0)); |
|
| 125 | 125 |
|
| 126 | 126 |
PASS(); |
| 127 | 127 |
} |
| ... | ... |
@@ -146,7 +146,7 @@ TEST test_choices_large_input() {
|
| 146 | 146 |
choices_search(&choices, "12"); |
| 147 | 147 |
|
| 148 | 148 |
/* Must match `seq 0 99999 | grep '.*1.*2.*' | wc -l` */ |
| 149 |
- ASSERT_EQ(8146, choices.available); |
|
| 149 |
+ ASSERT_INT_EQ(8146, choices.available); |
|
| 150 | 150 |
|
| 151 | 151 |
ASSERT_STR_EQ("12", choices_get(&choices, 0));
|
| 152 | 152 |
|
| ... | ... |
@@ -5,6 +5,9 @@ |
| 5 | 5 |
|
| 6 | 6 |
#include "greatest/greatest.h" |
| 7 | 7 |
|
| 8 |
+#define ASSERT_SCORE_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%f") |
|
| 9 |
+#define ASSERT_INT_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%d") |
|
| 10 |
+ |
|
| 8 | 11 |
/* has_match(char *needle, char *haystack) */ |
| 9 | 12 |
TEST exact_match_should_return_true() {
|
| 10 | 13 |
ASSERT(has_match("a", "a"));
|
| ... | ... |
@@ -76,63 +79,63 @@ TEST should_prefer_start_of_candidate() {
|
| 76 | 79 |
|
| 77 | 80 |
TEST score_exact_match() {
|
| 78 | 81 |
/* Exact match is SCORE_MAX */ |
| 79 |
- ASSERT_EQ(SCORE_MAX, match("abc", "abc"));
|
|
| 80 |
- ASSERT_EQ(SCORE_MAX, match("aBc", "abC"));
|
|
| 82 |
+ ASSERT_SCORE_EQ(SCORE_MAX, match("abc", "abc"));
|
|
| 83 |
+ ASSERT_SCORE_EQ(SCORE_MAX, match("aBc", "abC"));
|
|
| 81 | 84 |
PASS(); |
| 82 | 85 |
} |
| 83 | 86 |
|
| 84 | 87 |
TEST score_empty_query() {
|
| 85 | 88 |
/* Empty query always results in SCORE_MIN */ |
| 86 |
- ASSERT_EQ(SCORE_MIN, match("", ""));
|
|
| 87 |
- ASSERT_EQ(SCORE_MIN, match("", "a"));
|
|
| 88 |
- ASSERT_EQ(SCORE_MIN, match("", "bb"));
|
|
| 89 |
+ ASSERT_SCORE_EQ(SCORE_MIN, match("", ""));
|
|
| 90 |
+ ASSERT_SCORE_EQ(SCORE_MIN, match("", "a"));
|
|
| 91 |
+ ASSERT_SCORE_EQ(SCORE_MIN, match("", "bb"));
|
|
| 89 | 92 |
PASS(); |
| 90 | 93 |
} |
| 91 | 94 |
|
| 92 | 95 |
TEST score_gaps() {
|
| 93 |
- ASSERT_EQ(SCORE_GAP_LEADING, match("a", "*a"));
|
|
| 94 |
- ASSERT_EQ(SCORE_GAP_LEADING*2, match("a", "*ba"));
|
|
| 95 |
- ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_GAP_TRAILING, match("a", "**a*"));
|
|
| 96 |
- ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_GAP_TRAILING*2, match("a", "**a**"));
|
|
| 97 |
- ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CONSECUTIVE + SCORE_GAP_TRAILING*2, match("aa", "**aa**"));
|
|
| 98 |
- ASSERT_EQ(SCORE_GAP_LEADING + SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_GAP_TRAILING + SCORE_GAP_TRAILING, match("aa", "**a*a**"));
|
|
| 96 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING, match("a", "*a"));
|
|
| 97 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2, match("a", "*ba"));
|
|
| 98 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_GAP_TRAILING, match("a", "**a*"));
|
|
| 99 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_GAP_TRAILING*2, match("a", "**a**"));
|
|
| 100 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CONSECUTIVE + SCORE_GAP_TRAILING*2, match("aa", "**aa**"));
|
|
| 101 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_GAP_TRAILING + SCORE_GAP_TRAILING, match("aa", "**a*a**"));
|
|
| 99 | 102 |
PASS(); |
| 100 | 103 |
} |
| 101 | 104 |
|
| 102 | 105 |
TEST score_consecutive() {
|
| 103 |
- ASSERT_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CONSECUTIVE, match("aa", "*aa"));
|
|
| 104 |
- ASSERT_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CONSECUTIVE*2, match("aaa", "*aaa"));
|
|
| 105 |
- ASSERT_EQ(SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_MATCH_CONSECUTIVE, match("aaa", "*a*aa"));
|
|
| 106 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CONSECUTIVE, match("aa", "*aa"));
|
|
| 107 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CONSECUTIVE*2, match("aaa", "*aaa"));
|
|
| 108 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_MATCH_CONSECUTIVE, match("aaa", "*a*aa"));
|
|
| 106 | 109 |
PASS(); |
| 107 | 110 |
} |
| 108 | 111 |
|
| 109 | 112 |
TEST score_slash() {
|
| 110 |
- ASSERT_EQ(SCORE_GAP_LEADING + SCORE_MATCH_SLASH, match("a", "/a"));
|
|
| 111 |
- ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_SLASH, match("a", "*/a"));
|
|
| 112 |
- ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_SLASH + SCORE_MATCH_CONSECUTIVE, match("aa", "a/aa"));
|
|
| 113 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_MATCH_SLASH, match("a", "/a"));
|
|
| 114 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_SLASH, match("a", "*/a"));
|
|
| 115 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_SLASH + SCORE_MATCH_CONSECUTIVE, match("aa", "a/aa"));
|
|
| 113 | 116 |
PASS(); |
| 114 | 117 |
} |
| 115 | 118 |
|
| 116 | 119 |
TEST score_capital() {
|
| 117 |
- ASSERT_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CAPITAL, match("a", "bA"));
|
|
| 118 |
- ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CAPITAL, match("a", "baA"));
|
|
| 119 |
- ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CAPITAL + SCORE_MATCH_CONSECUTIVE, match("aa", "baAa"));
|
|
| 120 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CAPITAL, match("a", "bA"));
|
|
| 121 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CAPITAL, match("a", "baA"));
|
|
| 122 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CAPITAL + SCORE_MATCH_CONSECUTIVE, match("aa", "baAa"));
|
|
| 120 | 123 |
PASS(); |
| 121 | 124 |
} |
| 122 | 125 |
|
| 123 | 126 |
TEST score_dot() {
|
| 124 |
- ASSERT_EQ(SCORE_GAP_LEADING + SCORE_MATCH_DOT, match("a", ".a"));
|
|
| 125 |
- ASSERT_EQ(SCORE_GAP_LEADING*3 + SCORE_MATCH_DOT, match("a", "*a.a"));
|
|
| 126 |
- ASSERT_EQ(SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_MATCH_DOT, match("a", "*a.a"));
|
|
| 127 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_MATCH_DOT, match("a", ".a"));
|
|
| 128 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING*3 + SCORE_MATCH_DOT, match("a", "*a.a"));
|
|
| 129 |
+ ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_MATCH_DOT, match("a", "*a.a"));
|
|
| 127 | 130 |
PASS(); |
| 128 | 131 |
} |
| 129 | 132 |
|
| 130 | 133 |
TEST positions_consecutive() {
|
| 131 | 134 |
size_t positions[3]; |
| 132 | 135 |
match_positions("amo", "app/models/foo", positions);
|
| 133 |
- ASSERT_EQ(0, positions[0]); |
|
| 134 |
- ASSERT_EQ(4, positions[1]); |
|
| 135 |
- ASSERT_EQ(5, positions[2]); |
|
| 136 |
+ ASSERT_INT_EQ(0, positions[0]); |
|
| 137 |
+ ASSERT_INT_EQ(4, positions[1]); |
|
| 138 |
+ ASSERT_INT_EQ(5, positions[2]); |
|
| 136 | 139 |
|
| 137 | 140 |
PASS(); |
| 138 | 141 |
} |
| ... | ... |
@@ -144,10 +147,10 @@ TEST positions_start_of_word() {
|
| 144 | 147 |
*/ |
| 145 | 148 |
size_t positions[4]; |
| 146 | 149 |
match_positions("amor", "app/models/order", positions);
|
| 147 |
- ASSERT_EQ(0, positions[0]); |
|
| 148 |
- ASSERT_EQ(4, positions[1]); |
|
| 149 |
- ASSERT_EQ(11, positions[2]); |
|
| 150 |
- ASSERT_EQ(12, positions[3]); |
|
| 150 |
+ ASSERT_INT_EQ(0, positions[0]); |
|
| 151 |
+ ASSERT_INT_EQ(4, positions[1]); |
|
| 152 |
+ ASSERT_INT_EQ(11, positions[2]); |
|
| 153 |
+ ASSERT_INT_EQ(12, positions[3]); |
|
| 151 | 154 |
|
| 152 | 155 |
PASS(); |
| 153 | 156 |
} |
| ... | ... |
@@ -155,12 +158,12 @@ TEST positions_start_of_word() {
|
| 155 | 158 |
TEST positions_no_bonuses() {
|
| 156 | 159 |
size_t positions[2]; |
| 157 | 160 |
match_positions("as", "tags", positions);
|
| 158 |
- ASSERT_EQ(1, positions[0]); |
|
| 159 |
- ASSERT_EQ(3, positions[1]); |
|
| 161 |
+ ASSERT_INT_EQ(1, positions[0]); |
|
| 162 |
+ ASSERT_INT_EQ(3, positions[1]); |
|
| 160 | 163 |
|
| 161 | 164 |
match_positions("as", "examples.txt", positions);
|
| 162 |
- ASSERT_EQ(2, positions[0]); |
|
| 163 |
- ASSERT_EQ(7, positions[1]); |
|
| 165 |
+ ASSERT_INT_EQ(2, positions[0]); |
|
| 166 |
+ ASSERT_INT_EQ(7, positions[1]); |
|
| 164 | 167 |
|
| 165 | 168 |
PASS(); |
| 166 | 169 |
} |
| ... | ... |
@@ -168,9 +171,9 @@ TEST positions_no_bonuses() {
|
| 168 | 171 |
TEST positions_multiple_candidates_start_of_words() {
|
| 169 | 172 |
size_t positions[3]; |
| 170 | 173 |
match_positions("abc", "a/a/b/c/c", positions);
|
| 171 |
- ASSERT_EQ(2, positions[0]); |
|
| 172 |
- ASSERT_EQ(4, positions[1]); |
|
| 173 |
- ASSERT_EQ(6, positions[2]); |
|
| 174 |
+ ASSERT_INT_EQ(2, positions[0]); |
|
| 175 |
+ ASSERT_INT_EQ(4, positions[1]); |
|
| 176 |
+ ASSERT_INT_EQ(6, positions[2]); |
|
| 174 | 177 |
|
| 175 | 178 |
PASS(); |
| 176 | 179 |
} |
| ... | ... |
@@ -178,9 +181,9 @@ TEST positions_multiple_candidates_start_of_words() {
|
| 178 | 181 |
TEST positions_exact_match() {
|
| 179 | 182 |
size_t positions[3]; |
| 180 | 183 |
match_positions("foo", "foo", positions);
|
| 181 |
- ASSERT_EQ(0, positions[0]); |
|
| 182 |
- ASSERT_EQ(1, positions[1]); |
|
| 183 |
- ASSERT_EQ(2, positions[2]); |
|
| 184 |
+ ASSERT_INT_EQ(0, positions[0]); |
|
| 185 |
+ ASSERT_INT_EQ(1, positions[1]); |
|
| 186 |
+ ASSERT_INT_EQ(2, positions[2]); |
|
| 184 | 187 |
|
| 185 | 188 |
PASS(); |
| 186 | 189 |
} |