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