root/tests/lib/search/glob_prepare_replace_str.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-2024
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Andrew Borodin <aborodin@vmail.ru>, 2014
   9 
  10    This file is part of the Midnight Commander.
  11 
  12    The Midnight Commander is free software: you can redistribute it
  13    and/or modify it under the terms of the GNU General Public License as
  14    published by the Free Software Foundation, either version 3 of the License,
  15    or (at your option) any later version.
  16 
  17    The Midnight Commander is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20    GNU General Public License for more details.
  21 
  22    You should have received a copy of the GNU General Public License
  23    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24  */
  25 
  26 #define TEST_SUITE_NAME "lib/search/glob"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "glob.c"               /* for testing static functions */
  31 
  32 /* --------------------------------------------------------------------------------------------- */
  33 
  34 /* @DataSource("test_glob_prepare_replace_str_ds") */
  35 /* *INDENT-OFF* */
  36 static const struct test_glob_prepare_replace_str_ds
  37 {
  38     const char *input_value;
  39     const char *glob_str;
  40     const char *replace_str;
  41     const char *expected_result;
  42 } test_glob_prepare_replace_str_ds[] =
  43 {
  44     { /* 0. */
  45         "qqwwee",
  46         "*ww*",
  47         "\\1AA\\2",
  48         "qqAAee"
  49     },
  50     { /* 1. */
  51         "qqwwee",
  52         "*qq*",
  53         "\\1SS\\2",
  54         "SSwwee"
  55     },
  56     { /* 2. */
  57         "qqwwee",
  58         "*ee*",
  59         "\\1RR\\2",
  60         "qqwwRR"
  61     }
  62 };
  63 /* *INDENT-ON* */
  64 
  65 /* @Test(dataSource = "test_glob_prepare_replace_str_ds") */
  66 /* *INDENT-OFF* */
  67 START_PARAMETRIZED_TEST (test_glob_prepare_replace_str, test_glob_prepare_replace_str_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
  68 /* *INDENT-ON* */
  69 {
  70     /* given */
  71     mc_search_t *s;
  72     char *dest_str;
  73 
  74     s = mc_search_new (data->glob_str, NULL);
  75     s->is_case_sensitive = TRUE;
  76     s->search_type = MC_SEARCH_T_GLOB;
  77 
  78     /* when */
  79     mc_search_run (s, data->input_value, 0, strlen (data->input_value), NULL);
  80     dest_str = mc_search_prepare_replace_str2 (s, data->replace_str);
  81 
  82     /* then */
  83     mctest_assert_str_eq (dest_str, data->expected_result);
  84 
  85     g_free (dest_str);
  86     mc_search_free (s);
  87 }
  88 /* *INDENT-OFF* */
  89 END_PARAMETRIZED_TEST
  90 /* *INDENT-ON* */
  91 
  92 /* --------------------------------------------------------------------------------------------- */
  93 
  94 int
  95 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  96 {
  97     TCase *tc_core;
  98 
  99     tc_core = tcase_create ("Core");
 100 
 101     /* Add new tests here: *************** */
 102     mctest_add_parameterized_test (tc_core, test_glob_prepare_replace_str,
 103                                    test_glob_prepare_replace_str_ds);
 104     /* *********************************** */
 105 
 106     return mctest_run_all (tc_core);
 107 }
 108 
 109 /* --------------------------------------------------------------------------------------------- */

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