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