root/tests/lib/search/glob_translate_to_regex.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. START_PARAMETRIZED_TEST
  2. main

   1 /*
   2    libmc - checks for processing esc sequences in replace string
   3 
   4    Copyright (C) 2011-2019
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Andrew Borodin <aborodin@vmail.ru>, 2011
   9    Slava Zanko <slavazanko@gmail.com>, 2013
  10 
  11    This file is part of the Midnight Commander.
  12 
  13    The Midnight Commander is free software: you can redistribute it
  14    and/or modify it under the terms of the GNU General Public License as
  15    published by the Free Software Foundation, either version 3 of the License,
  16    or (at your option) any later version.
  17 
  18    The Midnight Commander is distributed in the hope that it will be useful,
  19    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21    GNU General Public License for more details.
  22 
  23    You should have received a copy of the GNU General Public License
  24    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  25  */
  26 
  27 #define TEST_SUITE_NAME "lib/search/glob"
  28 
  29 #include "tests/mctest.h"
  30 
  31 #include "glob.c"               /* for testing static functions */
  32 
  33 /* --------------------------------------------------------------------------------------------- */
  34 
  35 /* @DataSource("test_glob_translate_to_regex_ds") */
  36 /* *INDENT-OFF* */
  37 static const struct test_glob_translate_to_regex_ds
  38 {
  39     const char *input_value;
  40     const char *expected_result;
  41 } test_glob_translate_to_regex_ds[] =
  42 {
  43     {
  44         "test*",
  45         "test(.*)"
  46     },
  47     {
  48         "t?es*t",
  49         "t(.)es(.*)t"
  50     },
  51     {
  52         "te{st}",
  53         "te(st)"
  54     },
  55     {
  56         "te{st|ts}",
  57         "te(st|ts)"
  58     },
  59     {
  60         "te{st,ts}",
  61         "te(st|ts)"
  62     },
  63     {
  64         "te[st]",
  65         "te[st]"
  66     },
  67     {
  68         "t,e.st",
  69         "t,e\\.st"
  70     },
  71     {
  72         "^t,e.+st+$",
  73         "\\^t,e\\.\\+st\\+\\$"
  74     },
  75     {
  76         "te!@#$%^&*()_+|\";:'{}:><?\\?\\*.,/[]|\\/st",
  77         "te!@#\\$%\\^&(.*)\\(\\)_\\+|\";:'():><(.)\\?\\*\\.,/[]|\\/st"
  78     },
  79 };
  80 /* *INDENT-ON* */
  81 
  82 /* @Test(dataSource = "test_glob_translate_to_regex_ds") */
  83 /* *INDENT-OFF* */
  84 START_PARAMETRIZED_TEST (test_glob_translate_to_regex, test_glob_translate_to_regex_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
  85 /* *INDENT-ON* */
  86 {
  87     /* given */
  88     GString *tmp = g_string_new (data->input_value);
  89     GString *dest_str;
  90 
  91     /* when */
  92     dest_str = mc_search__glob_translate_to_regex (tmp);
  93 
  94     /* then */
  95     g_string_free (tmp, TRUE);
  96 
  97     mctest_assert_str_eq (dest_str->str, data->expected_result);
  98     g_string_free (dest_str, TRUE);
  99 }
 100 /* *INDENT-OFF* */
 101 END_PARAMETRIZED_TEST
 102 /* *INDENT-ON* */
 103 
 104 /* --------------------------------------------------------------------------------------------- */
 105 
 106 int
 107 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 108 {
 109     int number_failed;
 110 
 111     Suite *s = suite_create (TEST_SUITE_NAME);
 112     TCase *tc_core = tcase_create ("Core");
 113     SRunner *sr;
 114 
 115     /* Add new tests here: *************** */
 116     mctest_add_parameterized_test (tc_core, test_glob_translate_to_regex,
 117                                    test_glob_translate_to_regex_ds);
 118     /* *********************************** */
 119 
 120     suite_add_tcase (s, tc_core);
 121     sr = srunner_create (s);
 122     srunner_set_log (sr, "glob_translate_to_regex.log");
 123     srunner_run_all (sr, CK_ENV);
 124     number_failed = srunner_ntests_failed (sr);
 125     srunner_free (sr);
 126     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 127 }
 128 
 129 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */