| 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& remove_filename() |
| 17 | |
| 18 | #include <filesystem> |
| 19 | #include <type_traits> |
| 20 | #include <cassert> |
| 21 | |
| 22 | #include "test_iterators.h" |
| 23 | #include "count_new.h" |
| 24 | namespace fs = std::filesystem; |
| 25 | |
| 26 | struct RemoveFilenameTestcase { |
| 27 | const char* value; |
| 28 | const char* expect; |
| 29 | }; |
| 30 | |
| 31 | const RemoveFilenameTestcase TestCases[] = |
| 32 | { |
| 33 | {.value: "" , .expect: "" } |
| 34 | , {.value: "/" , .expect: "/" } |
| 35 | , {.value: "//" , .expect: "//" } |
| 36 | , {.value: "///" , .expect: "///" } |
| 37 | #ifdef _WIN32 |
| 38 | , {"\\" , "\\" } |
| 39 | #else |
| 40 | , {.value: "\\" , .expect: "" } |
| 41 | #endif |
| 42 | , {.value: "." , .expect: "" } |
| 43 | , {.value: ".." , .expect: "" } |
| 44 | , {.value: "/foo" , .expect: "/" } |
| 45 | , {.value: "foo/bar" , .expect: "foo/" } |
| 46 | , {.value: "foo/" , .expect: "foo/" } |
| 47 | #ifdef _WIN32 |
| 48 | , {"//foo" , "//foo" } |
| 49 | #else |
| 50 | , {.value: "//foo" , .expect: "//" } |
| 51 | #endif |
| 52 | , {.value: "//foo/" , .expect: "//foo/" } |
| 53 | , {.value: "//foo///" , .expect: "//foo///" } |
| 54 | , {.value: "///foo" , .expect: "///" } |
| 55 | , {.value: "///foo/" , .expect: "///foo/" } |
| 56 | , {.value: "/foo/" , .expect: "/foo/" } |
| 57 | , {.value: "/foo/." , .expect: "/foo/" } |
| 58 | , {.value: "/foo/.." , .expect: "/foo/" } |
| 59 | , {.value: "/foo/////" , .expect: "/foo/////" } |
| 60 | #ifdef _WIN32 |
| 61 | , {"/foo\\\\" , "/foo\\\\" } |
| 62 | #else |
| 63 | , {.value: "/foo\\\\" , .expect: "/" } |
| 64 | #endif |
| 65 | , {.value: "/foo//\\/" , .expect: "/foo//\\/" } |
| 66 | , {.value: "///foo" , .expect: "///" } |
| 67 | , {.value: "file.txt" , .expect: "" } |
| 68 | , {.value: "bar/../baz/./file.txt" , .expect: "bar/../baz/./" } |
| 69 | }; |
| 70 | |
| 71 | int main(int, char**) |
| 72 | { |
| 73 | using namespace fs; |
| 74 | for (auto const & TC : TestCases) { |
| 75 | path const p_orig(TC.value); |
| 76 | path p(p_orig); |
| 77 | assert(p == TC.value); |
| 78 | path& Ref = (p.remove_filename()); |
| 79 | assert(p == TC.expect); |
| 80 | assert(&Ref == &p); |
| 81 | assert(!p.has_filename()); |
| 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |