[Test,Helper] Add test for utf8_strncmp and fuzzy evaluate.

This commit is contained in:
Dave Davenport 2017-05-01 09:07:22 +02:00
parent bc428058cb
commit fb11b8ceb6
2 changed files with 28 additions and 1 deletions

View File

@ -244,7 +244,7 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st
* are found, respectively, to be less than, to match, or be greater than the first `n`
* characters (not bytes) of `b`.
*/
int utf8_strncmp ( const char *a, const char* b, size_t n );
int utf8_strncmp ( const char *a, const char* b, size_t n ) __attribute__((nonnull(1,2)));
/**
* @param wd The work directory (optional)

View File

@ -51,6 +51,14 @@ struct xcb_stuff *xcb;
abort ( ); \
} \
}
#define TASSERTL( a, b ) { \
if ( ( a ) == ( b ) ) { \
printf ( "Test %i passed (%s == %s) (%d == %d)\n", ++test, # a, # b, a, b ); \
}else { \
printf ( "Test %i failed (%s == %s) (%d != %d)\n", ++test, # a, # b, a, b ); \
abort ( ); \
} \
}
void rofi_add_error_message ( GString *msg )
{
@ -145,4 +153,23 @@ int main ( int argc, char ** argv )
TASSERT ( fd >= 0 );
remove_pid_file ( fd );
}
{
TASSERT ( utf8_strncmp ( "aapno", "aap€",3) == 0 );
TASSERT ( utf8_strncmp ( "aapno", "aap€",4) != 0 );
TASSERT ( utf8_strncmp ( "aapno", "a",4) != 0 );
TASSERT ( utf8_strncmp ( "a", "aap€",4) != 0 );
// char in[] = "Valid utf8 until \xc3\x28 we continue here";
// TASSERT ( utf8_strncmp ( in, "Valid", 3 ) == 0);
}
{
TASSERTL ( rofi_scorer_fuzzy_evaluate ("aap noot mies", 12 , "aap noot mies", 12), -605);
TASSERTL ( rofi_scorer_fuzzy_evaluate ("anm", 3, "aap noot mies", 12), -155);
TASSERTL ( rofi_scorer_fuzzy_evaluate ("blu", 3, "aap noot mies", 12), 1073741824);
config.case_sensitive = TRUE;
TASSERTL ( rofi_scorer_fuzzy_evaluate ("Anm", 3, "aap noot mies", 12), 1073741754);
config.case_sensitive = FALSE;
TASSERTL ( rofi_scorer_fuzzy_evaluate ("Anm", 3, "aap noot mies", 12), -155);
TASSERTL ( rofi_scorer_fuzzy_evaluate ("aap noot mies", 12,"Anm", 3 ), 1073741824);
}
}