libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

remove_filename.pass.cpp (1690B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: c++98, c++03
     11 
     12 // <filesystem>
     13 
     14 // class path
     15 
     16 // path& remove_filename()
     17 
     18 #include "filesystem_include.hpp"
     19 #include <type_traits>
     20 #include <cassert>
     21 
     22 #include "test_macros.h"
     23 #include "test_iterators.h"
     24 #include "count_new.hpp"
     25 #include "filesystem_test_helper.hpp"
     26 #include "verbose_assert.h"
     27 
     28 struct RemoveFilenameTestcase {
     29   const char* value;
     30   const char* expect;
     31 };
     32 
     33 const RemoveFilenameTestcase TestCases[] =
     34   {
     35       {"", ""}
     36     , {"/", "/"}
     37     , {"//", "//"}
     38     , {"///", "///"}
     39     , {"\\", ""}
     40     , {".", ""}
     41     , {"..", ""}
     42     , {"/foo", "/"}
     43     , {"foo/bar", "foo/"}
     44     , {"foo/", "foo/"}
     45     , {"//foo", "//"}
     46     , {"//foo/", "//foo/"}
     47     , {"//foo///", "//foo///"}
     48     , {"///foo", "///"}
     49     , {"///foo/", "///foo/"}
     50     , {"/foo/", "/foo/"}
     51     , {"/foo/.", "/foo/"}
     52     , {"/foo/..", "/foo/"}
     53     , {"/foo/////", "/foo/////"}
     54     , {"/foo\\\\", "/"}
     55     , {"/foo//\\/", "/foo//\\/"}
     56     , {"///foo", "///"}
     57     , {"file.txt", ""}
     58     , {"bar/../baz/./file.txt", "bar/../baz/./"}
     59   };
     60 
     61 int main()
     62 {
     63   using namespace fs;
     64   for (auto const & TC : TestCases) {
     65     path const p_orig(TC.value);
     66     path p(p_orig);
     67     assert(p == TC.value);
     68     path& Ref = (p.remove_filename());
     69     ASSERT_EQ(p, TC.expect) << DISPLAY(p_orig);
     70     assert(&Ref == &p);
     71     assert(!p.has_filename());
     72   }
     73 }