2017-04-15 10:32:05 +00: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 17:34:03 +00: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 12:54:21 +00:00
|
|
|
#include "display.h"
|
2017-05-31 22:12:03 +00:00
|
|
|
#include "xcb.h"
|
2016-10-20 17:34:03 +00:00
|
|
|
#include "xcb-internal.h"
|
|
|
|
#include "rofi.h"
|
|
|
|
#include "settings.h"
|
2017-09-29 06:32:09 +00:00
|
|
|
#include "rofi-types.h"
|
2016-10-20 17:34:03 +00:00
|
|
|
|
2017-09-29 16:44:21 +00:00
|
|
|
#include <check.h>
|
2016-10-20 17:34:03 +00:00
|
|
|
|
2017-05-03 15:57:08 +00:00
|
|
|
void rofi_add_error_message ( G_GNUC_UNUSED GString *msg )
|
2017-01-09 22:15:45 +00:00
|
|
|
{
|
|
|
|
}
|
2016-10-20 17:34:03 +00:00
|
|
|
int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
|
|
|
|
{
|
|
|
|
fputs ( msg, stderr );
|
|
|
|
return TRUE;
|
|
|
|
}
|
2017-05-31 22:12:03 +00:00
|
|
|
int monitor_active ( G_GNUC_UNUSED workarea *mon )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2016-10-20 17:34:03 +00:00
|
|
|
|
2017-06-02 12:54:21 +00: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 16:44:21 +00:00
|
|
|
START_TEST(test_tokenizer_free )
|
|
|
|
{
|
2017-10-01 08:51:02 +00:00
|
|
|
helper_tokenize_free ( NULL );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
START_TEST ( test_tokenizer_match_normal_single_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_NORMAL;
|
2017-10-01 08:51:02 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
|
2017-06-02 12:54:21 +00:00
|
|
|
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_normal_single_cs )
|
2016-10-20 17:34:03 +00:00
|
|
|
{
|
2017-09-29 16:44:21 +00:00
|
|
|
config.matching_method = MM_NORMAL;
|
2019-02-02 11:07:36 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_normal_multiple_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_NORMAL;
|
2019-02-02 11:07:36 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_normal_single_ci_negate )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_NORMAL;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "-noot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_normal_multiple_ci_negate )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_NORMAL;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "-noot aap", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_single_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_single_cs )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_multiple_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_single_ci_question )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "n?ot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_single_ci_star )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "n*ot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_glob_multiple_ci_star )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_GLOB;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "n* ot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_fuzzy_single_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_FUZZY;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_fuzzy_single_cs )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_FUZZY;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_fuzzy_multiple_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_FUZZY;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
|
2017-10-01 08:51:02 +00:00
|
|
|
tokens = helper_tokenize ( "n ot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_fuzzy_single_ci_split )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_FUZZY;
|
2019-02-02 11:07:36 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "ont", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_fuzzy_multiple_ci_split )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_FUZZY;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "o n t", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_single_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_single_cs )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "noot", TRUE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_multiple_ci )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "no ot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_single_ci_dq )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "n.?ot", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_single_two_char )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "n[oa]{2}t", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST ( test_tokenizer_match_regex_single_two_word_till_end )
|
|
|
|
{
|
|
|
|
config.matching_method = MM_REGEX;
|
2019-02-02 10:45:28 +00:00
|
|
|
rofi_int_matcher **tokens = helper_tokenize ( "^(aap|noap)\\sMie.*", FALSE );
|
2017-09-29 16:44:21 +00: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 08:51:02 +00:00
|
|
|
helper_tokenize_free ( tokens );
|
2017-09-29 16:44:21 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2017-10-01 08:51:02 +00:00
|
|
|
static Suite * helper_tokenizer_suite (void)
|
2017-09-29 16:44:21 +00:00
|
|
|
{
|
|
|
|
Suite *s;
|
|
|
|
|
|
|
|
s = suite_create("Tokenizer");
|
|
|
|
|
|
|
|
/* Core test case */
|
2016-10-20 17:34:03 +00:00
|
|
|
{
|
2017-09-29 16:44:21 +00: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 17:34:03 +00:00
|
|
|
}
|
|
|
|
{
|
2017-09-29 16:44:21 +00: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 17:34:03 +00:00
|
|
|
}
|
|
|
|
{
|
2017-09-29 16:44:21 +00: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 17:34:03 +00:00
|
|
|
}
|
|
|
|
{
|
2017-09-29 16:44:21 +00: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 17:34:03 +00:00
|
|
|
}
|
|
|
|
{
|
2017-09-29 16:44:21 +00: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char ** argv )
|
|
|
|
{
|
|
|
|
if ( setlocale ( LC_ALL, "" ) == NULL ) {
|
|
|
|
fprintf ( stderr, "Failed to set locale.\n" );
|
|
|
|
return EXIT_FAILURE;
|
2016-10-20 17:34:03 +00:00
|
|
|
}
|
2017-09-29 16:44:21 +00:00
|
|
|
|
|
|
|
int number_failed = 0;
|
|
|
|
Suite *s;
|
|
|
|
SRunner *sr;
|
|
|
|
|
2017-10-01 08:51:02 +00:00
|
|
|
s = helper_tokenizer_suite();
|
2017-09-29 16:44:21 +00: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;
|
|
|
|
|
2016-10-20 17:34:03 +00:00
|
|
|
}
|