| 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++03, c++11, c++14 |
| 10 |
// UNSUPPORTED: availability-filesystem-missing |
| 11 |
|
| 12 |
// <filesystem> |
| 13 |
|
| 14 |
// class path |
| 15 |
|
| 16 |
// path& replace_extension(path const& p = path()) |
| 17 |
|
| 18 |
#include <filesystem> |
| 19 |
#include <cassert> |
| 20 |
#include <string> |
| 21 |
#include <type_traits> |
| 22 |
|
| 23 |
#include "count_new.h" |
| 24 |
#include "test_iterators.h" |
| 25 |
namespace fs = std::filesystem; |
| 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 |
} |