Manual pages: mcmcdiffmceditmcview

root/tests/lib/name_quote.c

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

DEFINITIONS

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

   1 /*
   2    lib - Quote file names
   3 
   4    Copyright (C) 2011-2026
   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 <https://www.gnu.org/licenses/>.
  24  */
  25 
  26 #define TEST_SUITE_NAME "/lib/util"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "lib/util.h"
  31 
  32 /* --------------------------------------------------------------------------------------------- */
  33 
  34 /* @DataSource("data_source1") */
  35 static const struct data_source1
  36 {
  37     gboolean input_quote_percent;
  38     const char *input_string;
  39 
  40     const char *expected_string;
  41 } data_source1[] = {
  42     { TRUE, "%%", "%%%%" },
  43     { FALSE, "%%", "%%" },
  44 };
  45 
  46 /* @Test(dataSource = "data_source1") */
  47 START_PARAMETRIZED_TEST (quote_percent_test, data_source1)
     /* [previous][next][first][last][top][bottom][index][help]  */
  48 {
  49     // given
  50     GString *actual_string;
  51 
  52     // when
  53     actual_string = name_quote (data->input_string, data->input_quote_percent);
  54 
  55     // then
  56     mctest_assert_str_eq (actual_string->str, data->expected_string);
  57 
  58     g_string_free (actual_string, TRUE);
  59 }
  60 END_PARAMETRIZED_TEST
  61 
  62 /* --------------------------------------------------------------------------------------------- */
  63 
  64 /* @DataSource("data_source2") */
  65 static const struct data_source2
  66 {
  67     const char *input_string;
  68 
  69     const char *expected_string;
  70 } data_source2[] = {
  71     { "", NULL },
  72     { "-", "./-" },
  73     { "blabla-", "blabla-" },
  74     { "\r\n\t", "\\\r\\\n\\\t" },
  75     { "'\\\";?|[]{}<>`!$&*()", "\\'\\\\\\\"\\;\\?\\|\\[\\]\\{\\}\\<\\>\\`\\!\\$\\&\\*\\(\\)" },
  76     { "a b c ", "a\\ b\\ c\\ " },
  77     { "#", "\\#" },
  78     { "blabla#", "blabla#" },
  79     { "~", "\\~" },
  80     { "blabla~", "blabla~" },
  81     {
  82         NULL,
  83         NULL,
  84     },
  85 };
  86 
  87 /* @Test(dataSource = "data_source2") */
  88 START_PARAMETRIZED_TEST (name_quote_test, data_source2)
     /* [previous][next][first][last][top][bottom][index][help]  */
  89 {
  90     // given
  91     GString *actual_string;
  92 
  93     // when
  94     actual_string = name_quote (data->input_string, FALSE);
  95 
  96     // then
  97     if (actual_string == NULL)
  98     {
  99         mctest_assert_ptr_eq (NULL, data->expected_string);
 100     }
 101     else
 102     {
 103         mctest_assert_str_eq (actual_string->str, data->expected_string);
 104         g_string_free (actual_string, TRUE);
 105     }
 106 }
 107 END_PARAMETRIZED_TEST
 108 
 109 /* --------------------------------------------------------------------------------------------- */
 110 
 111 int
 112 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 113 {
 114     TCase *tc_core;
 115 
 116     tc_core = tcase_create ("Core");
 117 
 118     // Add new tests here: ***************
 119     mctest_add_parameterized_test (tc_core, quote_percent_test, data_source1);
 120     mctest_add_parameterized_test (tc_core, name_quote_test, data_source2);
 121     // ***********************************
 122 
 123     return mctest_run_all (tc_core);
 124 }
 125 
 126 /* --------------------------------------------------------------------------------------------- */

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