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++03 10 11 // <filesystem> 12 13 // class path 14 15 // path& remove_filename() 16 17 #include "filesystem_include.h" 18 #include <type_traits> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "test_iterators.h" 23 #include "count_new.h" 24 #include "filesystem_test_helper.h" 25 26 struct RemoveFilenameTestcase { 27 const char* value; 28 const char* expect; 29 }; 30 31 const RemoveFilenameTestcase TestCases[] = 32 { 33 {"", ""} 34 , {"/", "/"} 35 , {"//", "//"} 36 , {"///", "///"} 37 #ifdef _WIN32 38 , {"\\", "\\"} 39 #else 40 , {"\\", ""} 41 #endif 42 , {".", ""} 43 , {"..", ""} 44 , {"/foo", "/"} 45 , {"foo/bar", "foo/"} 46 , {"foo/", "foo/"} 47 #ifdef _WIN32 48 , {"//foo", "//foo"} 49 #else 50 , {"//foo", "//"} 51 #endif 52 , {"//foo/", "//foo/"} 53 , {"//foo///", "//foo///"} 54 , {"///foo", "///"} 55 , {"///foo/", "///foo/"} 56 , {"/foo/", "/foo/"} 57 , {"/foo/.", "/foo/"} 58 , {"/foo/..", "/foo/"} 59 , {"/foo/////", "/foo/////"} 60 #ifdef _WIN32 61 , {"/foo\\\\", "/foo\\\\"} 62 #else 63 , {"/foo\\\\", "/"} 64 #endif 65 , {"/foo//\\/", "/foo//\\/"} 66 , {"///foo", "///"} 67 , {"file.txt", ""} 68 , {"bar/../baz/./file.txt", "bar/../baz/./"} 69 }; 70 71 int main(int, char**) 72 { 73 using namespace fs; 74 for (auto const & TC : TestCases) { 75 path const p_orig(TC.value); 76 path p(p_orig); 77 assert(p == TC.value); 78 path& Ref = (p.remove_filename()); 79 assert(p == TC.expect); 80 assert(&Ref == &p); 81 assert(!p.has_filename()); 82 } 83 84 return 0; 85 } 86