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// <experimental/filesystem> 13 14// class path 15 16// path& remove_filename() 17 18#include <experimental/filesystem> 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 27namespace fs = std::experimental::filesystem; 28 29struct RemoveFilenameTestcase { 30 const char* value; 31 const char* expect; 32}; 33 34const RemoveFilenameTestcase TestCases[] = 35 { 36 {"", ""} 37 , {"/", ""} 38 , {"//", ""} 39 , {"///", ""} 40 , {"\\", ""} 41 , {".", ""} 42 , {"..", ""} 43 , {"/foo", "/"} 44 , {"//foo", ""} 45 , {"//foo/", ""} 46 , {"//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 60int main() 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(p == TC.expect); 69 assert(&Ref == &p); 70 { 71 const path parentp = p_orig.parent_path(); 72 if (parentp == p_orig.root_name()) { 73 74 assert(p.empty()); 75 } else { 76 assert(p == parentp); 77 } 78 } 79 } 80} 81