1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++98, c++03 10 11 // <filesystem> 12 13 // class path 14 15 // path& remove_filename() 16 17 #include "filesystem_include.hpp" 18 #include <type_traits> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "test_iterators.h" 23 #include "count_new.hpp" 24 #include "filesystem_test_helper.hpp" 25 #include "verbose_assert.h" 26 27 struct RemoveFilenameTestcase { 28 const char* value; 29 const char* expect; 30 }; 31 32 const RemoveFilenameTestcase TestCases[] = 33 { 34 {"", ""} 35 , {"/", "/"} 36 , {"//", "//"} 37 , {"///", "///"} 38 , {"\\", ""} 39 , {".", ""} 40 , {"..", ""} 41 , {"/foo", "/"} 42 , {"foo/bar", "foo/"} 43 , {"foo/", "foo/"} 44 , {"//foo", "//"} 45 , {"//foo/", "//foo/"} 46 , {"//foo///", "//foo///"} 47 , {"///foo", "///"} 48 , {"///foo/", "///foo/"} 49 , {"/foo/", "/foo/"} 50 , {"/foo/.", "/foo/"} 51 , {"/foo/..", "/foo/"} 52 , {"/foo/////", "/foo/////"} 53 , {"/foo\\\\", "/"} 54 , {"/foo//\\/", "/foo//\\/"} 55 , {"///foo", "///"} 56 , {"file.txt", ""} 57 , {"bar/../baz/./file.txt", "bar/../baz/./"} 58 }; 59 60 int main(int, char**) 61 { 62 using namespace fs; 63 for (auto const & TC : TestCases) { 64 path const p_orig(TC.value); 65 path p(p_orig); 66 assert(p == TC.value); 67 path& Ref = (p.remove_filename()); 68 ASSERT_EQ(p, TC.expect) << DISPLAY(p_orig); 69 assert(&Ref == &p); 70 assert(!p.has_filename()); 71 } 72 73 return 0; 74 } 75