fzy

terminal fuzzy finder picker

git clone https://9o.is/git/fzy.git

commit 260121118f46ead06a90feca14ed6c65e8d8ee53
parent 34c15394333dce229eddca2757c72e2d2cc1e0be
Author: John Hawthorn <john.hawthorn@gmail.com>
Date:   Sat, 26 Jul 2014 21:09:53 -0700

Replace test "framework" with way less magic

Diffstat:
Mfzytest.c | 44++++++++++++++++++++++++++++----------------
1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/fzytest.c b/fzytest.c @@ -1,14 +1,17 @@ #include <stdio.h> #include "fzy.h" -const char *testname; int testsrun = 0, testspassed = 0; -#define TEST(name) int test_##name(){ testname = #name; testsrun++; do -#define ENDTEST while(0); testspassed++; return 0;} -#define assert(x) if(!(x)){fprintf(stderr, "test \"%s\" failed\n assert(%s) was false\n at %s:%i\n\n", testname, #x, __FILE__ ,__LINE__);return -1;} +#define assert(x) if(!(x)){fprintf(stderr, "test \"%s\" failed\n assert(%s) was false\n at %s:%i\n\n", __func__, #x, __FILE__ ,__LINE__);return -1;} -TEST(match){ +void runtest(int (*test)()){ + testsrun++; + if(!test()) + testspassed++; +} + +int test_match(){ assert(has_match("a", "a")); assert(has_match("a", "ab")); assert(has_match("a", "ba")); @@ -21,25 +24,31 @@ TEST(match){ /* match when query is empty */ assert(has_match("", "")); assert(has_match("", "a")); -}ENDTEST -TEST(scoring){ + return 0; +} + +int test_scoring(){ /* App/Models/Order is better than App/MOdels/foo */ assert(match("amo", "app/models/foo") < match("amo", "app/models/order")); /* App/MOdels/foo is better than App/M/fOo */ assert(match("amo", "app/m/foo") < match("amo", "app/models/foo")); -}ENDTEST -TEST(positions_1){ + return 0; +} + +int test_positions_1(){ size_t positions[3]; match_positions("amo", "app/models/foo", positions); assert(positions[0] == 0); assert(positions[1] == 4); assert(positions[2] == 5); -}ENDTEST -TEST(positions_2){ + return 0; +} + +int test_positions_2(){ /* * We should prefer matching the 'o' in order, since it's the beginning * of a word. @@ -49,7 +58,9 @@ TEST(positions_2){ assert(positions[0] == 0); assert(positions[1] == 4); assert(positions[2] == 11); -}ENDTEST + + return 0; +} void summary(){ printf("%i tests run: %i passed %i failed\n", testsrun, testspassed, testsrun - testspassed); @@ -58,10 +69,11 @@ void summary(){ int main(int argc, char *argv[]){ (void) argc; (void) argv; - test_match(); - test_scoring(); - test_positions_1(); - test_positions_2(); + + runtest(test_match); + runtest(test_scoring); + runtest(test_positions_1); + runtest(test_positions_2); summary();