2017-04-15 06:32:05 -04:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
|
|
|
* Copyright © 2013-2017 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-10-20 13:34:03 -04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <helper.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <xcb/xcb_ewmh.h>
|
2017-06-02 08:54:21 -04:00
|
|
|
#include "display.h"
|
2021-06-05 06:58:07 -04:00
|
|
|
#include "theme.h"
|
2017-05-31 18:12:03 -04:00
|
|
|
#include "xcb.h"
|
2016-10-20 13:34:03 -04:00
|
|
|
#include "xcb-internal.h"
|
|
|
|
#include "rofi.h"
|
|
|
|
#include "settings.h"
|
2017-09-29 02:32:09 -04:00
|
|
|
#include "rofi-types.h"
|
2021-06-05 06:58:07 -04:00
|
|
|
#include "widgets/textbox.h"
|
2021-06-15 06:55:03 -04:00
|
|
|
#include "rofi-icon-fetcher.h"
|
2016-10-20 13:34:03 -04:00
|
|
|
|
2017-09-29 12:44:21 -04:00
|
|
|
#include <check.h>
|
2016-10-20 13:34:03 -04:00
|
|
|
|
2021-06-05 06:58:07 -04:00
|
|
|
ThemeWidget *rofi_theme = NULL;
|
|
|
|
|
2021-06-15 06:31:32 -04:00
|
|
|
uint32_t rofi_icon_fetcher_query ( const char *name, const int size )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2021-06-15 18:11:57 -04:00
|
|
|
uint32_t rofi_icon_fetcher_query_advanced ( const char *name, const int wsize, const int hsize )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2021-07-06 17:49:17 -04:00
|
|
|
void rofi_clear_error_messages ( void ) {}
|
2021-06-15 06:31:32 -04:00
|
|
|
|
|
|
|
cairo_surface_t * rofi_icon_fetcher_get ( const uint32_t uid )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-06-05 06:58:07 -04:00
|
|
|
gboolean rofi_theme_parse_string ( G_GNUC_UNUSED const char *string )
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-08-14 07:03:16 -04:00
|
|
|
double textbox_get_estimated_char_height ( void )
|
2021-06-05 06:58:07 -04:00
|
|
|
{
|
|
|
|
return 12.0;
|
|
|
|
}
|
|
|
|
void rofi_view_get_current_monitor ( int *width, int *height )
|
|
|
|
{
|
|
|
|
*width = 1920;
|
|
|
|
*height = 1080;
|
|
|
|
}
|
|
|
|
double textbox_get_estimated_ch ( void )
|
|
|
|
{
|
|
|
|
return 9.0;
|
|
|
|
}
|
2017-05-03 11:57:08 -04:00
|
|
|
void rofi_add_error_message ( G_GNUC_UNUSED GString *msg )
|
2017-01-09 17:15:45 -05:00
|
|
|
{
|
|
|
|
}
|
2016-10-20 13:34:03 -04:00
|
|
|
int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
|
|
|
|
{
|
|
|
|
fputs ( msg, stderr );
|
|
|
|
return TRUE;
|
|
|
|
}
|
2017-05-31 18:12:03 -04:00
|
|
|
int monitor_active ( G_GNUC_UNUSED workarea *mon )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2016-10-20 13:34:03 -04:00
|
|
|
|
2017-06-02 08:54:21 -04:00
|
|
|
void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data )
|
|
|
|
{
|
|
|
|
}
|
2017-09-29 12:44:21 -04:00
|
|
|
START_TEST(test_tokenizer_free )
|
|
|
|
{
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( NULL );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
START_TEST ( test_tokenizer_match_normal_single_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_NORMAL;
|
2017-10-01 04:51:02 -04:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
|
2017-06-02 08:54:21 -04:00
|
|
|
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , TRUE );
|
|
|
|
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_normal_single_cs )
|
2016-10-20 13:34:03 -04:00
|
|
|
{
|
2017-09-29 12:44:21 -04:00
|
|
|
config.matching_method = MM_NORMAL;
|
2019-02-02 06:07:36 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , FALSE );
|
|
|
|
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_normal_multiple_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_NORMAL;
|
2019-02-02 06:07:36 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_normal_single_ci_negate )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_NORMAL;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "-noot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_normal_multiple_ci_negate )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_NORMAL;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "-noot aap", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , FALSE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_single_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , TRUE );
|
|
|
|
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_single_cs )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , FALSE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_multiple_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_single_ci_question )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "n?ot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , FALSE);
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_single_ci_star )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "n*ot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE);
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_multiple_ci_star )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "n* ot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE);
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "ot nap mies") , TRUE);
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_fuzzy_single_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_FUZZY;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , TRUE );
|
|
|
|
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_fuzzy_single_cs )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_FUZZY;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , FALSE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_fuzzy_multiple_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_FUZZY;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
2017-10-01 04:51:02 -04:00
|
|
|
tokens = helper_tokenize ( "n ot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE);
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_fuzzy_single_ci_split )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_FUZZY;
|
2019-02-02 06:07:36 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "ont", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , FALSE);
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap nmiest") , TRUE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_fuzzy_multiple_ci_split )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_FUZZY;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "o n t", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE);
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "ot nap mies") , TRUE);
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_single_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , TRUE );
|
|
|
|
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_single_cs )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap Noot mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "Nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noOTap mies") , FALSE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_multiple_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_single_ci_dq )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "n.?ot", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , FALSE);
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_single_two_char )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "n[oa]{2}t", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , TRUE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noat miesot") , TRUE);
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noaat miesot") , FALSE);
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_single_two_word_till_end )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 05:45:28 -05:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "^(aap|noap)\\sMie.*", FALSE );
|
2017-09-29 12:44:21 -04:00
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap noot mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "aap mies") , TRUE);
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nooaap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "nootap mies") , FALSE );
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "noap miesot") , TRUE);
|
|
|
|
ck_assert_int_eq ( helper_token_match ( tokens, "ot nap mies") , FALSE );
|
2017-10-01 04:51:02 -04:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 12:44:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2017-10-01 04:51:02 -04:00
|
|
|
static Suite * helper_tokenizer_suite (void)
|
2017-09-29 12:44:21 -04:00
|
|
|
{
|
|
|
|
Suite *s;
|
|
|
|
|
|
|
|
s = suite_create("Tokenizer");
|
|
|
|
|
|
|
|
/* Core test case */
|
2016-10-20 13:34:03 -04:00
|
|
|
{
|
2017-09-29 12:44:21 -04:00
|
|
|
TCase *tc_core;
|
|
|
|
tc_core = tcase_create("Core");
|
|
|
|
tcase_add_test(tc_core, test_tokenizer_free);
|
|
|
|
suite_add_tcase(s, tc_core);
|
2016-10-20 13:34:03 -04:00
|
|
|
}
|
|
|
|
{
|
2017-09-29 12:44:21 -04:00
|
|
|
TCase *tc_normal = tcase_create ("Normal");
|
|
|
|
tcase_add_test(tc_normal, test_tokenizer_match_normal_single_ci );
|
|
|
|
tcase_add_test(tc_normal, test_tokenizer_match_normal_single_cs );
|
|
|
|
tcase_add_test(tc_normal, test_tokenizer_match_normal_multiple_ci );
|
|
|
|
tcase_add_test(tc_normal, test_tokenizer_match_normal_single_ci_negate );
|
|
|
|
tcase_add_test(tc_normal, test_tokenizer_match_normal_multiple_ci_negate);
|
|
|
|
suite_add_tcase(s, tc_normal);
|
2016-10-20 13:34:03 -04:00
|
|
|
}
|
|
|
|
{
|
2017-09-29 12:44:21 -04:00
|
|
|
TCase *tc_glob = tcase_create ("Glob");
|
|
|
|
tcase_add_test(tc_glob, test_tokenizer_match_glob_single_ci);
|
|
|
|
tcase_add_test(tc_glob, test_tokenizer_match_glob_single_cs);
|
|
|
|
tcase_add_test(tc_glob, test_tokenizer_match_glob_multiple_ci);
|
|
|
|
tcase_add_test(tc_glob, test_tokenizer_match_glob_single_ci_question);
|
|
|
|
tcase_add_test(tc_glob, test_tokenizer_match_glob_single_ci_star);
|
|
|
|
tcase_add_test(tc_glob, test_tokenizer_match_glob_multiple_ci_star);
|
|
|
|
suite_add_tcase(s, tc_glob);
|
2016-10-20 13:34:03 -04:00
|
|
|
}
|
|
|
|
{
|
2017-09-29 12:44:21 -04:00
|
|
|
TCase *tc_fuzzy = tcase_create ("Fuzzy");
|
|
|
|
tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_single_ci);
|
|
|
|
tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_single_cs);
|
|
|
|
tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_single_ci_split);
|
|
|
|
tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_multiple_ci);
|
|
|
|
tcase_add_test(tc_fuzzy, test_tokenizer_match_fuzzy_multiple_ci_split);
|
|
|
|
suite_add_tcase(s, tc_fuzzy);
|
2016-10-20 13:34:03 -04:00
|
|
|
}
|
|
|
|
{
|
2017-09-29 12:44:21 -04:00
|
|
|
TCase *tc_regex = tcase_create ("Regex");
|
|
|
|
tcase_add_test(tc_regex, test_tokenizer_match_regex_single_ci);
|
|
|
|
tcase_add_test(tc_regex, test_tokenizer_match_regex_single_cs);
|
|
|
|
tcase_add_test(tc_regex, test_tokenizer_match_regex_single_ci_dq);
|
|
|
|
tcase_add_test(tc_regex, test_tokenizer_match_regex_single_two_char);
|
|
|
|
tcase_add_test(tc_regex, test_tokenizer_match_regex_single_two_word_till_end);
|
|
|
|
tcase_add_test(tc_regex, test_tokenizer_match_regex_multiple_ci);
|
|
|
|
suite_add_tcase(s, tc_regex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-08-14 07:03:16 -04:00
|
|
|
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
2017-09-29 12:44:21 -04:00
|
|
|
{
|
|
|
|
if ( setlocale ( LC_ALL, "" ) == NULL ) {
|
|
|
|
fprintf ( stderr, "Failed to set locale.\n" );
|
|
|
|
return EXIT_FAILURE;
|
2016-10-20 13:34:03 -04:00
|
|
|
}
|
2017-09-29 12:44:21 -04:00
|
|
|
|
|
|
|
int number_failed = 0;
|
|
|
|
Suite *s;
|
|
|
|
SRunner *sr;
|
|
|
|
|
2017-10-01 04:51:02 -04:00
|
|
|
s = helper_tokenizer_suite();
|
2017-09-29 12:44:21 -04:00
|
|
|
sr = srunner_create(s);
|
|
|
|
|
|
|
|
srunner_run_all(sr, CK_NORMAL);
|
|
|
|
number_failed = srunner_ntests_failed(sr);
|
|
|
|
srunner_free(sr);
|
|
|
|
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
2021-06-05 06:58:07 -04:00
|
|
|
|
2016-10-20 13:34:03 -04:00
|
|
|
}
|