Manual pages: mcmcdiffmceditmcview

root/tests/lib/strutil/str_rstrip_eol.c

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

DEFINITIONS

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

   1 /*
   2    lib/strutil - tests for lib/strutil.c:str_rstrip_eol function
   3 
   4    Copyright (C) 2025
   5    Free Software Foundation, Inc.
   6 
   7    This file is part of the Midnight Commander.
   8 
   9    The Midnight Commander is free software: you can redistribute it
  10    and/or modify it under the terms of the GNU General Public License as
  11    published by the Free Software Foundation, either version 3 of the License,
  12    or (at your option) any later version.
  13 
  14    The Midnight Commander is distributed in the hope that it will be useful,
  15    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17    GNU General Public License for more details.
  18 
  19    You should have received a copy of the GNU General Public License
  20    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  21  */
  22 
  23 #define TEST_SUITE_NAME "/lib/strutil"
  24 
  25 #include "tests/mctest.h"
  26 
  27 #include "lib/strutil.h"
  28 
  29 /* --------------------------------------------------------------------------------------------- */
  30 
  31 /* @DataSource("str_rstrip_eol_test_ds1") */
  32 /* Testcases are taken from Glib */
  33 static const struct str_rstrip_eol_test_struct
  34 {
  35     const char *input_string;
  36     const char *expected_result;
  37 } str_rstrip_eol_test_ds1[] = {
  38     {
  39         "",
  40         "",
  41     },
  42     {
  43         " \n\r",
  44         " \n",
  45     },
  46     {
  47         " \t\r\n",
  48         " \t",
  49     },
  50     {
  51         "a \r ",
  52         "a \r ",
  53     },
  54     {
  55         " a  \n ",
  56         " a  \n ",
  57     },
  58     {
  59         "a a\n\r\n",
  60         "a a\n",
  61     },
  62     {
  63         "\na a \r",
  64         "\na a ",
  65     },
  66 };
  67 
  68 /* @Test(dataSource = "str_rstrip_eol_test_ds1") */
  69 START_TEST (str_rstrip_eol_test1)
     /* [previous][next][first][last][top][bottom][index][help]  */
  70 {
  71     /* given */
  72     const struct str_rstrip_eol_test_struct *data = &str_rstrip_eol_test_ds1[_i];
  73 
  74     /* when */
  75     char *actual_result = g_strdup (data->input_string);
  76     str_rstrip_eol (actual_result);
  77 
  78     /* then */
  79     ck_assert_str_eq (actual_result, data->expected_result);
  80 
  81     g_free (actual_result);
  82 }
  83 
  84 END_TEST
  85 /* --------------------------------------------------------------------------------------------- */
  86 START_TEST (str_rstrip_eol_test_null)
     /* [previous][next][first][last][top][bottom][index][help]  */
  87 {
  88     char *ptr = NULL;
  89     str_rstrip_eol (ptr);
  90     ck_assert_ptr_null (ptr);
  91 }
  92 
  93 END_TEST
  94 /* --------------------------------------------------------------------------------------------- */
  95 int
  96 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  97 {
  98     TCase *tc_core;
  99 
 100     tc_core = tcase_create ("Core");
 101 
 102     /* Add new tests here: *************** */
 103     mctest_add_parameterized_test (tc_core, str_rstrip_eol_test1, str_rstrip_eol_test_ds1);
 104     tcase_add_test (tc_core, str_rstrip_eol_test_null);
 105     /* *********************************** */
 106 
 107     return mctest_run_all (tc_core);
 108 }
 109 
 110 /* --------------------------------------------------------------------------------------------- */

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