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