replace_extension.pass.cpp (1717B)
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_extension(path const& p = path()) 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 27 28 struct ReplaceExtensionTestcase { 29 const char* value; 30 const char* expect; 31 const char* extension; 32 }; 33 34 const ReplaceExtensionTestcase TestCases[] = 35 { 36 {"", "", ""} 37 , {"foo.cpp", "foo", ""} 38 , {"foo.cpp", "foo.", "."} 39 , {"foo..cpp", "foo..txt", "txt"} 40 , {"", ".txt", "txt"} 41 , {"", ".txt", ".txt"} 42 , {"/foo", "/foo.txt", ".txt"} 43 , {"/foo", "/foo.txt", "txt"} 44 , {"/foo.cpp", "/foo.txt", ".txt"} 45 , {"/foo.cpp", "/foo.txt", "txt"} 46 }; 47 const ReplaceExtensionTestcase NoArgCases[] = 48 { 49 {"", "", ""} 50 , {"foo", "foo", ""} 51 , {"foo.cpp", "foo", ""} 52 , {"foo..cpp", "foo.", ""} 53 }; 54 55 int main() 56 { 57 using namespace fs; 58 for (auto const & TC : TestCases) { 59 path p(TC.value); 60 assert(p == TC.value); 61 path& Ref = (p.replace_extension(TC.extension)); 62 assert(p == TC.expect); 63 assert(&Ref == &p); 64 } 65 for (auto const& TC : NoArgCases) { 66 path p(TC.value); 67 assert(p == TC.value); 68 path& Ref = (p.replace_extension()); 69 assert(p == TC.expect); 70 assert(&Ref == &p); 71 } 72 }