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& replace_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 #include "verbose_assert.h" 26 27 struct ReplaceFilenameTestcase { 28 const char* value; 29 const char* expect; 30 const char* filename; 31 }; 32 33 const ReplaceFilenameTestcase TestCases[] = 34 { 35 {"/foo", "/bar", "bar"} 36 , {"/foo", "/", ""} 37 , {"foo", "bar", "bar"} 38 , {"/", "/bar", "bar"} 39 , {"\\", "bar", "bar"} 40 , {"///", "///bar", "bar"} 41 , {"\\\\", "bar", "bar"} 42 , {"\\/\\", "\\/bar", "bar"} 43 , {".", "bar", "bar"} 44 , {"..", "bar", "bar"} 45 , {"/foo\\baz/bong/", "/foo\\baz/bong/bar", "bar"} 46 , {"/foo\\baz/bong", "/foo\\baz/bar", "bar"} 47 }; 48 49 int main(int, char**) 50 { 51 using namespace fs; 52 for (auto const & TC : TestCases) { 53 path p(TC.value); 54 ASSERT_EQ(p, TC.value); 55 path& Ref = (p.replace_filename(TC.filename)); 56 ASSERT_EQ(p, TC.expect) 57 << DISPLAY(TC.value) 58 << DISPLAY(TC.filename); 59 assert(&Ref == &p); 60 // Tests Effects "as-if": remove_filename() append(filename) 61 { 62 path p2(TC.value); 63 path replace(TC.filename); 64 p2.remove_filename(); 65 p2 /= replace; 66 ASSERT_EQ(p, p2); 67 } 68 } 69 70 return 0; 71 } 72