73 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <filesystem>12 13// class path14 15// path& replace_extension(path const& p = path())16 17#include <filesystem>18#include <cassert>19#include <string>20#include <type_traits>21 22#include "count_new.h"23#include "test_iterators.h"24namespace fs = std::filesystem;25 26struct ReplaceExtensionTestcase {27 const char* value;28 const char* expect;29 const char* extension;30};31 32const ReplaceExtensionTestcase TestCases[] =33 {34 {"", "", ""}35 , {"foo.cpp", "foo", ""}36 , {"foo.cpp", "foo.", "."}37 , {"foo..cpp", "foo..txt", "txt"}38 , {"", ".txt", "txt"}39 , {"", ".txt", ".txt"}40 , {"/foo", "/foo.txt", ".txt"}41 , {"/foo", "/foo.txt", "txt"}42 , {"/foo.cpp", "/foo.txt", ".txt"}43 , {"/foo.cpp", "/foo.txt", "txt"}44 };45const ReplaceExtensionTestcase NoArgCases[] =46 {47 {"", "", ""}48 , {"foo", "foo", ""}49 , {"foo.cpp", "foo", ""}50 , {"foo..cpp", "foo.", ""}51};52 53int main(int, char**)54{55 using namespace fs;56 for (auto const & TC : TestCases) {57 path p(TC.value);58 assert(p == TC.value);59 path& Ref = (p.replace_extension(TC.extension));60 assert(p == TC.expect);61 assert(&Ref == &p);62 }63 for (auto const& TC : NoArgCases) {64 path p(TC.value);65 assert(p == TC.value);66 path& Ref = (p.replace_extension());67 assert(p == TC.expect);68 assert(&Ref == &p);69 }70 71 return 0;72}73