From ec5d25fe15f7887d8da3ac92a006ca27bd6a32db Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sun, 16 Apr 2017 23:12:21 -0700 Subject: Format values in errored tests --- test/test_choices.c | 72 +++++++++++++++++++++++----------------------- test/test_match.c | 83 +++++++++++++++++++++++++++-------------------------- 2 files changed, 79 insertions(+), 76 deletions(-) diff --git a/test/test_choices.c b/test/test_choices.c index 9e4b025..9e0ae7d 100644 --- a/test/test_choices.c +++ b/test/test_choices.c @@ -8,7 +8,7 @@ #include "greatest/greatest.h" -#define ASSERT_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%d") +#define ASSERT_INT_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%d") static options_t default_options; static choices_t choices; @@ -26,15 +26,15 @@ static void teardown(void *udata) { } TEST test_choices_empty() { - ASSERT_EQ(0, choices.size); - ASSERT_EQ(0, choices.available); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.size); + ASSERT_INT_EQ(0, choices.available); + ASSERT_INT_EQ(0, choices.selection); choices_prev(&choices); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.selection); choices_next(&choices); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.selection); PASS(); } @@ -43,21 +43,21 @@ TEST test_choices_1() { choices_add(&choices, "tags"); choices_search(&choices, ""); - ASSERT_EQ(1, choices.available); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(1, choices.available); + ASSERT_INT_EQ(0, choices.selection); choices_search(&choices, "t"); - ASSERT_EQ(1, choices.available); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(1, choices.available); + ASSERT_INT_EQ(0, choices.selection); choices_prev(&choices); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.selection); choices_next(&choices); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.selection); ASSERT(!strcmp(choices_get(&choices, 0), "tags")); - ASSERT_EQ(NULL, choices_get(&choices, 1)); + ASSERT_INT_EQ(NULL, choices_get(&choices, 1)); PASS(); } @@ -68,40 +68,40 @@ TEST test_choices_2() { /* Empty search */ choices_search(&choices, ""); - ASSERT_EQ(0, choices.selection); - ASSERT_EQ(2, choices.available); + ASSERT_INT_EQ(0, choices.selection); + ASSERT_INT_EQ(2, choices.available); choices_next(&choices); - ASSERT_EQ(1, choices.selection); + ASSERT_INT_EQ(1, choices.selection); choices_next(&choices); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.selection); choices_prev(&choices); - ASSERT_EQ(1, choices.selection); + ASSERT_INT_EQ(1, choices.selection); choices_prev(&choices); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.selection); /* Filtered search */ choices_search(&choices, "te"); - ASSERT_EQ(1, choices.available); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(1, choices.available); + ASSERT_INT_EQ(0, choices.selection); ASSERT_STR_EQ("test", choices_get(&choices, 0)); choices_next(&choices); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.selection); choices_prev(&choices); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.selection); /* No results */ choices_search(&choices, "foobar"); - ASSERT_EQ(0, choices.available); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.available); + ASSERT_INT_EQ(0, choices.selection); /* Different order due to scoring */ choices_search(&choices, "ts"); - ASSERT_EQ(2, choices.available); - ASSERT_EQ(0, choices.selection); + ASSERT_INT_EQ(2, choices.available); + ASSERT_INT_EQ(0, choices.selection); ASSERT_STR_EQ("test", choices_get(&choices, 0)); ASSERT_STR_EQ("tags", choices_get(&choices, 1)); @@ -111,17 +111,17 @@ TEST test_choices_2() { TEST test_choices_without_search() { /* Before a search is run, it should return no results */ - ASSERT_EQ(0, choices.available); - ASSERT_EQ(0, choices.selection); - ASSERT_EQ(0, choices.size); - ASSERT_EQ(NULL, choices_get(&choices, 0)); + ASSERT_INT_EQ(0, choices.available); + ASSERT_INT_EQ(0, choices.selection); + ASSERT_INT_EQ(0, choices.size); + ASSERT_INT_EQ(NULL, choices_get(&choices, 0)); choices_add(&choices, "test"); - ASSERT_EQ(0, choices.available); - ASSERT_EQ(0, choices.selection); - ASSERT_EQ(1, choices.size); - ASSERT_EQ(NULL, choices_get(&choices, 0)); + ASSERT_INT_EQ(0, choices.available); + ASSERT_INT_EQ(0, choices.selection); + ASSERT_INT_EQ(1, choices.size); + ASSERT_INT_EQ(NULL, choices_get(&choices, 0)); PASS(); } @@ -146,7 +146,7 @@ TEST test_choices_large_input() { choices_search(&choices, "12"); /* Must match `seq 0 99999 | grep '.*1.*2.*' | wc -l` */ - ASSERT_EQ(8146, choices.available); + ASSERT_INT_EQ(8146, choices.available); ASSERT_STR_EQ("12", choices_get(&choices, 0)); diff --git a/test/test_match.c b/test/test_match.c index 5117666..00dcdb0 100644 --- a/test/test_match.c +++ b/test/test_match.c @@ -5,6 +5,9 @@ #include "greatest/greatest.h" +#define ASSERT_SCORE_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%f") +#define ASSERT_INT_EQ(a,b) ASSERT_EQ_FMT((a), (b), "%d") + /* has_match(char *needle, char *haystack) */ TEST exact_match_should_return_true() { ASSERT(has_match("a", "a")); @@ -76,63 +79,63 @@ TEST should_prefer_start_of_candidate() { TEST score_exact_match() { /* Exact match is SCORE_MAX */ - ASSERT_EQ(SCORE_MAX, match("abc", "abc")); - ASSERT_EQ(SCORE_MAX, match("aBc", "abC")); + ASSERT_SCORE_EQ(SCORE_MAX, match("abc", "abc")); + ASSERT_SCORE_EQ(SCORE_MAX, match("aBc", "abC")); PASS(); } TEST score_empty_query() { /* Empty query always results in SCORE_MIN */ - ASSERT_EQ(SCORE_MIN, match("", "")); - ASSERT_EQ(SCORE_MIN, match("", "a")); - ASSERT_EQ(SCORE_MIN, match("", "bb")); + ASSERT_SCORE_EQ(SCORE_MIN, match("", "")); + ASSERT_SCORE_EQ(SCORE_MIN, match("", "a")); + ASSERT_SCORE_EQ(SCORE_MIN, match("", "bb")); PASS(); } TEST score_gaps() { - ASSERT_EQ(SCORE_GAP_LEADING, match("a", "*a")); - ASSERT_EQ(SCORE_GAP_LEADING*2, match("a", "*ba")); - ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_GAP_TRAILING, match("a", "**a*")); - ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_GAP_TRAILING*2, match("a", "**a**")); - ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CONSECUTIVE + SCORE_GAP_TRAILING*2, match("aa", "**aa**")); - ASSERT_EQ(SCORE_GAP_LEADING + SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_GAP_TRAILING + SCORE_GAP_TRAILING, match("aa", "**a*a**")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING, match("a", "*a")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2, match("a", "*ba")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_GAP_TRAILING, match("a", "**a*")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_GAP_TRAILING*2, match("a", "**a**")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CONSECUTIVE + SCORE_GAP_TRAILING*2, match("aa", "**aa**")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_GAP_TRAILING + SCORE_GAP_TRAILING, match("aa", "**a*a**")); PASS(); } TEST score_consecutive() { - ASSERT_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CONSECUTIVE, match("aa", "*aa")); - ASSERT_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CONSECUTIVE*2, match("aaa", "*aaa")); - ASSERT_EQ(SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_MATCH_CONSECUTIVE, match("aaa", "*a*aa")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CONSECUTIVE, match("aa", "*aa")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CONSECUTIVE*2, match("aaa", "*aaa")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_MATCH_CONSECUTIVE, match("aaa", "*a*aa")); PASS(); } TEST score_slash() { - ASSERT_EQ(SCORE_GAP_LEADING + SCORE_MATCH_SLASH, match("a", "/a")); - ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_SLASH, match("a", "*/a")); - ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_SLASH + SCORE_MATCH_CONSECUTIVE, match("aa", "a/aa")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_MATCH_SLASH, match("a", "/a")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_SLASH, match("a", "*/a")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_SLASH + SCORE_MATCH_CONSECUTIVE, match("aa", "a/aa")); PASS(); } TEST score_capital() { - ASSERT_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CAPITAL, match("a", "bA")); - ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CAPITAL, match("a", "baA")); - ASSERT_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CAPITAL + SCORE_MATCH_CONSECUTIVE, match("aa", "baAa")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_MATCH_CAPITAL, match("a", "bA")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CAPITAL, match("a", "baA")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING*2 + SCORE_MATCH_CAPITAL + SCORE_MATCH_CONSECUTIVE, match("aa", "baAa")); PASS(); } TEST score_dot() { - ASSERT_EQ(SCORE_GAP_LEADING + SCORE_MATCH_DOT, match("a", ".a")); - ASSERT_EQ(SCORE_GAP_LEADING*3 + SCORE_MATCH_DOT, match("a", "*a.a")); - ASSERT_EQ(SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_MATCH_DOT, match("a", "*a.a")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_MATCH_DOT, match("a", ".a")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING*3 + SCORE_MATCH_DOT, match("a", "*a.a")); + ASSERT_SCORE_EQ(SCORE_GAP_LEADING + SCORE_GAP_INNER + SCORE_MATCH_DOT, match("a", "*a.a")); PASS(); } TEST positions_consecutive() { size_t positions[3]; match_positions("amo", "app/models/foo", positions); - ASSERT_EQ(0, positions[0]); - ASSERT_EQ(4, positions[1]); - ASSERT_EQ(5, positions[2]); + ASSERT_INT_EQ(0, positions[0]); + ASSERT_INT_EQ(4, positions[1]); + ASSERT_INT_EQ(5, positions[2]); PASS(); } @@ -144,10 +147,10 @@ TEST positions_start_of_word() { */ size_t positions[4]; match_positions("amor", "app/models/order", positions); - ASSERT_EQ(0, positions[0]); - ASSERT_EQ(4, positions[1]); - ASSERT_EQ(11, positions[2]); - ASSERT_EQ(12, positions[3]); + ASSERT_INT_EQ(0, positions[0]); + ASSERT_INT_EQ(4, positions[1]); + ASSERT_INT_EQ(11, positions[2]); + ASSERT_INT_EQ(12, positions[3]); PASS(); } @@ -155,12 +158,12 @@ TEST positions_start_of_word() { TEST positions_no_bonuses() { size_t positions[2]; match_positions("as", "tags", positions); - ASSERT_EQ(1, positions[0]); - ASSERT_EQ(3, positions[1]); + ASSERT_INT_EQ(1, positions[0]); + ASSERT_INT_EQ(3, positions[1]); match_positions("as", "examples.txt", positions); - ASSERT_EQ(2, positions[0]); - ASSERT_EQ(7, positions[1]); + ASSERT_INT_EQ(2, positions[0]); + ASSERT_INT_EQ(7, positions[1]); PASS(); } @@ -168,9 +171,9 @@ TEST positions_no_bonuses() { TEST positions_multiple_candidates_start_of_words() { size_t positions[3]; match_positions("abc", "a/a/b/c/c", positions); - ASSERT_EQ(2, positions[0]); - ASSERT_EQ(4, positions[1]); - ASSERT_EQ(6, positions[2]); + ASSERT_INT_EQ(2, positions[0]); + ASSERT_INT_EQ(4, positions[1]); + ASSERT_INT_EQ(6, positions[2]); PASS(); } @@ -178,9 +181,9 @@ TEST positions_multiple_candidates_start_of_words() { TEST positions_exact_match() { size_t positions[3]; match_positions("foo", "foo", positions); - ASSERT_EQ(0, positions[0]); - ASSERT_EQ(1, positions[1]); - ASSERT_EQ(2, positions[2]); + ASSERT_INT_EQ(0, positions[0]); + ASSERT_INT_EQ(1, positions[1]); + ASSERT_INT_EQ(2, positions[2]); PASS(); } -- cgit v1.2.3