root/tests/lib/strutil/str_rstrip_eol.c

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

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. START_TEST
  4. START_TEST
  5. 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 /* @Before */
  32 static void
  33 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  34 {
  35 }
  36 
  37 /* --------------------------------------------------------------------------------------------- */
  38 
  39 /* @After */
  40 static void
  41 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  42 {
  43 }
  44 
  45 /* --------------------------------------------------------------------------------------------- */
  46 
  47 /* @DataSource("str_rstrip_eol_test_ds1") */
  48 /* Testcases are taken from Glib */
  49 static const struct str_rstrip_eol_test_struct
  50 {
  51     const char *input_string;
  52     const char *expected_result;
  53 } str_rstrip_eol_test_ds1[] = {
  54     {
  55         "",
  56         "",
  57     },
  58     {
  59         " \n\r",
  60         " \n",
  61     },
  62     {
  63         " \t\r\n",
  64         " \t",
  65     },
  66     {
  67         "a \r ",
  68         "a \r ",
  69     },
  70     {
  71         " a  \n ",
  72         " a  \n ",
  73     },
  74     {
  75         "a a\n\r\n",
  76         "a a\n",
  77     },
  78     {
  79         "\na a \r",
  80         "\na a ",
  81     },
  82 };
  83 
  84 /* @Test(dataSource = "str_rstrip_eol_test_ds1") */
  85 START_TEST (str_rstrip_eol_test1)
     /* [previous][next][first][last][top][bottom][index][help]  */
  86 {
  87     /* given */
  88     const struct str_rstrip_eol_test_struct *data = &str_rstrip_eol_test_ds1[_i];
  89 
  90     /* when */
  91     char *actual_result = g_strdup (data->input_string);
  92     str_rstrip_eol (actual_result);
  93 
  94     /* then */
  95     ck_assert_str_eq (actual_result, data->expected_result);
  96 
  97     g_free (actual_result);
  98 }
  99 
 100 END_TEST
 101 /* --------------------------------------------------------------------------------------------- */
 102 START_TEST (str_rstrip_eol_test_null)
     /* [previous][next][first][last][top][bottom][index][help]  */
 103 {
 104     char *ptr = NULL;
 105     str_rstrip_eol (ptr);
 106     ck_assert_ptr_null (ptr);
 107 }
 108 
 109 END_TEST
 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     tcase_add_checked_fixture (tc_core, setup, teardown);
 119 
 120     /* Add new tests here: *************** */
 121     mctest_add_parameterized_test (tc_core, str_rstrip_eol_test1, str_rstrip_eol_test_ds1);
 122     tcase_add_test (tc_core, str_rstrip_eol_test_null);
 123     /* *********************************** */
 124 
 125     return mctest_run_all (tc_core);
 126 }
 127 
 128 /* --------------------------------------------------------------------------------------------- */

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