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