root/tests/lib/search/regex_process_escape_sequence.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-2018
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Slava Zanko <slavazanko@gmail.com>, 2011, 2013
   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/regex"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "regex.c"              /* for testing static functions */
  31 
  32 /* --------------------------------------------------------------------------------------------- */
  33 
  34 /* @DataSource("test_regex_process_escape_sequence_ds") */
  35 /* *INDENT-OFF* */
  36 static const struct test_regex_process_escape_sequence_ds
  37 {
  38     const char *input_from;
  39     const replace_transform_type_t input_initial_flags;
  40     const gboolean input_use_utf;
  41     const char *expected_string;
  42 } test_regex_process_escape_sequence_ds[] =
  43 {
  44     { /* 0. */
  45         "{101}",
  46         REPLACE_T_NO_TRANSFORM,
  47         FALSE,
  48         "A"
  49     },
  50     { /* 1. */
  51         "x42",
  52         REPLACE_T_NO_TRANSFORM,
  53         FALSE,
  54         "B"
  55     },
  56     { /* 2. */
  57         "x{444}",
  58         REPLACE_T_NO_TRANSFORM,
  59         FALSE,
  60         "D"
  61     },
  62     { /* 3. */
  63         "x{444}",
  64         REPLACE_T_NO_TRANSFORM,
  65         TRUE,
  66         "ф"
  67     },
  68     { /* 4. */
  69         "n",
  70         REPLACE_T_NO_TRANSFORM,
  71         FALSE,
  72         "\n"
  73     },
  74     { /* 5. */
  75         "t",
  76         REPLACE_T_NO_TRANSFORM,
  77         FALSE,
  78         "\t"
  79     },
  80     { /* 6. */
  81         "v",
  82         REPLACE_T_NO_TRANSFORM,
  83         FALSE,
  84         "\v"
  85     },
  86     { /* 7. */
  87         "b",
  88         REPLACE_T_NO_TRANSFORM,
  89         FALSE,
  90         "\b"
  91     },
  92     { /* 8. */
  93         "r",
  94         REPLACE_T_NO_TRANSFORM,
  95         FALSE,
  96         "\r"
  97     },
  98     { /* 9. */
  99         "f",
 100         REPLACE_T_NO_TRANSFORM,
 101         FALSE,
 102         "\f"
 103     },
 104     { /* 10. */
 105         "a",
 106         REPLACE_T_NO_TRANSFORM,
 107         FALSE,
 108         "\a"
 109     },
 110 };
 111 /* *INDENT-ON* */
 112 
 113 /* @Test(dataSource = "test_regex_process_escape_sequence_ds") */
 114 /* *INDENT-OFF* */
 115 START_PARAMETRIZED_TEST (test_regex_process_escape_sequence, test_regex_process_escape_sequence_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 116 /* *INDENT-ON* */
 117 {
 118     /* given */
 119     GString *actual_string;
 120     replace_transform_type_t replace_flags = REPLACE_T_NO_TRANSFORM;
 121 
 122     replace_flags = data->input_initial_flags;
 123     actual_string = g_string_new ("");
 124 
 125     /* when */
 126     mc_search_regex__process_escape_sequence (actual_string, data->input_from, -1, &replace_flags,
 127                                               data->input_use_utf);
 128 
 129     /* then */
 130     mctest_assert_str_eq (actual_string->str, data->expected_string);
 131 
 132     g_string_free (actual_string, TRUE);
 133 }
 134 /* *INDENT-OFF* */
 135 END_PARAMETRIZED_TEST
 136 /* *INDENT-ON* */
 137 
 138 /* --------------------------------------------------------------------------------------------- */
 139 
 140 int
 141 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 142 {
 143     int number_failed;
 144 
 145     Suite *s = suite_create (TEST_SUITE_NAME);
 146     TCase *tc_core = tcase_create ("Core");
 147     SRunner *sr;
 148 
 149     /* Add new tests here: *************** */
 150     mctest_add_parameterized_test (tc_core, test_regex_process_escape_sequence,
 151                                    test_regex_process_escape_sequence_ds);
 152     /* *********************************** */
 153 
 154     suite_add_tcase (s, tc_core);
 155     sr = srunner_create (s);
 156     srunner_set_log (sr, "regex_process_escape_sequence.log");
 157     srunner_run_all (sr, CK_ENV);
 158     number_failed = srunner_ntests_failed (sr);
 159     srunner_free (sr);
 160     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 161 }
 162 
 163 /* --------------------------------------------------------------------------------------------- */

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