Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 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& remove_filename() |
| 17 | |
Eric Fiselier | f1471a3 | 2018-03-26 05:46:57 +0000 | [diff] [blame] | 18 | #include "filesystem_include.hpp" |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 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 | |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 27 | |
| 28 | struct RemoveFilenameTestcase { |
| 29 | const char* value; |
| 30 | const char* expect; |
| 31 | }; |
| 32 | |
| 33 | const RemoveFilenameTestcase TestCases[] = |
| 34 | { |
| 35 | {"", ""} |
| 36 | , {"/", ""} |
Eric Fiselier | 620a9a5 | 2016-10-15 22:37:42 +0000 | [diff] [blame] | 37 | , {"//", ""} |
| 38 | , {"///", ""} |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 39 | , {"\\", ""} |
| 40 | , {".", ""} |
| 41 | , {"..", ""} |
| 42 | , {"/foo", "/"} |
Eric Fiselier | 620a9a5 | 2016-10-15 22:37:42 +0000 | [diff] [blame] | 43 | , {"//foo", ""} |
| 44 | , {"//foo/", ""} |
| 45 | , {"//foo///", ""} |
| 46 | , {"///foo", "/"} |
| 47 | , {"///foo/", "///foo"} |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 48 | , {"/foo/", "/foo"} |
| 49 | , {"/foo/.", "/foo"} |
| 50 | , {"/foo/..", "/foo"} |
| 51 | , {"/foo/////", "/foo"} |
| 52 | , {"/foo\\\\", "/"} |
| 53 | , {"/foo//\\/", "/foo//\\"} |
Eric Fiselier | 620a9a5 | 2016-10-15 22:37:42 +0000 | [diff] [blame] | 54 | , {"///foo", "/"} |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 55 | , {"file.txt", ""} |
| 56 | , {"bar/../baz/./file.txt", "bar/../baz/."} |
| 57 | }; |
| 58 | |
| 59 | int main() |
| 60 | { |
| 61 | using namespace fs; |
| 62 | for (auto const & TC : TestCases) { |
| 63 | path const p_orig(TC.value); |
| 64 | path p(p_orig); |
| 65 | assert(p == TC.value); |
| 66 | path& Ref = (p.remove_filename()); |
| 67 | assert(p == TC.expect); |
| 68 | assert(&Ref == &p); |
| 69 | { |
| 70 | const path parentp = p_orig.parent_path(); |
| 71 | if (parentp == p_orig.root_name()) { |
| 72 | |
| 73 | assert(p.empty()); |
| 74 | } else { |
| 75 | assert(p == parentp); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |