LCOV - code coverage report
Current view: top level - tests - catch_pathinfo.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 41 41 100.0 %
Date: 2022-02-13 10:56:14 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2021-2022  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/snapdev
       4             : // contact@m2osw.com
       5             : //
       6             : // This program is free software; you can redistribute it and/or modify
       7             : // it under the terms of the GNU General Public License as published by
       8             : // the Free Software Foundation; either version 2 of the License, or
       9             : // (at your option) any later version.
      10             : //
      11             : // This program is distributed in the hope that it will be useful,
      12             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             : // GNU General Public License for more details.
      15             : //
      16             : // You should have received a copy of the GNU General Public License along
      17             : // with this program; if not, write to the Free Software Foundation, Inc.,
      18             : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             : 
      20             : /** \file
      21             :  * \brief Verify that the path functions work.
      22             :  *
      23             :  * This file implements tests for the pathinfo function.
      24             :  */
      25             : 
      26             : // self
      27             : //
      28             : #include    <snapdev/pathinfo.h>
      29             : 
      30             : #include    "catch_main.h"
      31             : 
      32             : 
      33             : // C++ lib
      34             : //
      35             : #include    <set>
      36             : 
      37             : 
      38             : // last include
      39             : //
      40             : #include    <snapdev/poison.h>
      41             : 
      42             : 
      43             : 
      44             : 
      45           7 : CATCH_TEST_CASE("pathinfo_replace_suffix", "[pathinfo]")
      46             : {
      47          10 :     CATCH_START_SECTION("pathinfo: replace existing suffix")
      48             :     {
      49           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
      50             :                   "/full/path/example/pathinfo.cpp"
      51             :                 , ".cpp"
      52             :                 , ".h") == "/full/path/example/pathinfo.h");
      53             : 
      54           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
      55             :                   "/full/path/example/pathinfo.h"
      56             :                 , ".h"
      57             :                 , ".cpp") == "/full/path/example/pathinfo.cpp");
      58             : 
      59           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
      60             :                   "relative/path/pathinfo.cpp"
      61             :                 , ".cpp"
      62             :                 , ".h") == "relative/path/pathinfo.h");
      63             : 
      64           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
      65             :                   "relative/path/pathinfo.h"
      66             :                 , ".h"
      67             :                 , ".cpp") == "relative/path/pathinfo.cpp");
      68             : 
      69           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
      70             :                   "no-path.cpp"
      71             :                 , ".cpp"
      72             :                 , ".h") == "no-path.h");
      73             : 
      74           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
      75             :                   "no-path.h"
      76             :                 , ".h"
      77             :                 , ".cpp") == "no-path.cpp");
      78             :     }
      79             :     CATCH_END_SECTION()
      80             : 
      81          10 :     CATCH_START_SECTION("pathinfo: replace non-existant suffix")
      82             :     {
      83           2 :         std::string full_path_c("/full/path/example/pathinfo.c");
      84           2 :         std::string full_path_hpp("/full/path/example/pathinfo.hpp");
      85             : 
      86           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix(
      87             :                   full_path_c
      88             :                 , ".cpp"
      89             :                 , ".h") == "/full/path/example/pathinfo.c.h");
      90             : 
      91           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix(
      92             :                   full_path_hpp
      93             :                 , ".h"
      94             :                 , ".cpp") == "/full/path/example/pathinfo.hpp.cpp");
      95             : 
      96           2 :         std::string relative_path_c("relative/path/pathinfo.c");
      97           2 :         std::string relative_path_hpp("relative/path/pathinfo.hpp");
      98             : 
      99           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix(
     100             :                   relative_path_c
     101             :                 , ".cpp"
     102             :                 , ".h") == "relative/path/pathinfo.c.h");
     103             : 
     104           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix(
     105             :                   relative_path_hpp
     106             :                 , ".h"
     107             :                 , ".cpp") == "relative/path/pathinfo.hpp.cpp");
     108             : 
     109           2 :         std::string no_path_c("no-path.c");
     110           2 :         std::string no_path_hpp("no-path.hpp");
     111             : 
     112           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix(
     113             :                   no_path_c
     114             :                 , ".cpp"
     115             :                 , ".h") == "no-path.c.h");
     116             : 
     117           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix(
     118             :                   no_path_hpp
     119             :                 , ".h"
     120             :                 , ".cpp") == "no-path.hpp.cpp");
     121             :     }
     122             :     CATCH_END_SECTION()
     123             : 
     124          10 :     CATCH_START_SECTION("pathinfo: remove suffix when present")
     125             :     {
     126           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     127             :                   "/full/path/example/pathinfo.cpp"
     128             :                 , ".cpp") == "/full/path/example/pathinfo");
     129             : 
     130           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     131             :                   "/full/path/example/pathinfo.h"
     132             :                 , ".h") == "/full/path/example/pathinfo");
     133             : 
     134           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     135             :                   "relative/path/pathinfo.cpp"
     136             :                 , ".cpp") == "relative/path/pathinfo");
     137             : 
     138           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     139             :                   "relative/path/pathinfo.h"
     140             :                 , ".h") == "relative/path/pathinfo");
     141             : 
     142           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     143             :                   "no-path.cpp"
     144             :                 , ".cpp") == "no-path");
     145             : 
     146           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     147             :                   "no-path.h"
     148             :                 , ".h") == "no-path");
     149             :     }
     150             :     CATCH_END_SECTION()
     151             : 
     152          10 :     CATCH_START_SECTION("pathinfo: remove suffix when absent")
     153             :     {
     154           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     155             :                   "/full/path/example/pathinfo.c"
     156             :                 , ".cpp") == "/full/path/example/pathinfo.c");
     157             : 
     158           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     159             :                   "/full/path/example/pathinfo.hpp"
     160             :                 , ".h") == "/full/path/example/pathinfo.hpp");
     161             : 
     162           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     163             :                   "relative/path/pathinfo.c"
     164             :                 , ".cpp") == "relative/path/pathinfo.c");
     165             : 
     166           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     167             :                   "relative/path/pathinfo.hpp"
     168             :                 , ".h") == "relative/path/pathinfo.hpp");
     169             : 
     170           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     171             :                   "no-path.c"
     172             :                 , ".cpp") == "no-path.c");
     173             : 
     174           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     175             :                   "no-path.hpp"
     176             :                 , ".h") == "no-path.hpp");
     177             :     }
     178             :     CATCH_END_SECTION()
     179             : 
     180          10 :     CATCH_START_SECTION("pathinfo: do nothing if non-existant suffix")
     181             :     {
     182           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     183             :                   "/full/path/example/pathinfo.c"
     184             :                 , ".cpp"
     185             :                 , ".h"
     186             :                 , true) == "/full/path/example/pathinfo.c");
     187             : 
     188           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     189             :                   "/full/path/example/pathinfo.c"
     190             :                 , ".cpp"
     191             :                 , ""
     192             :                 , true) == "/full/path/example/pathinfo.c");
     193             : 
     194           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     195             :                   "/full/path/example/pathinfo.hpp"
     196             :                 , ".h"
     197             :                 , ".cpp"
     198             :                 , true) == "/full/path/example/pathinfo.hpp");
     199             : 
     200           1 :         CATCH_REQUIRE(snapdev::pathinfo::replace_suffix<std::string>(
     201             :                   "/full/path/example/pathinfo.hpp"
     202             :                 , ".h"
     203             :                 , std::string()
     204             :                 , true) == "/full/path/example/pathinfo.hpp");
     205             :     }
     206             :     CATCH_END_SECTION()
     207          11 : }
     208             : 
     209             : 
     210             : 
     211             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13