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" |
Eric Fiselier | 1e34c76 | 2018-04-02 23:03:41 +0000 | [diff] [blame^] | 26 | #include "verbose_assert.h" |
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 | {"", ""} |
Eric Fiselier | 1e34c76 | 2018-04-02 23:03:41 +0000 | [diff] [blame^] | 36 | , {"/", "/"} |
| 37 | , {"//", "//"} |
| 38 | , {"///", "///"} |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 39 | , {"\\", ""} |
| 40 | , {".", ""} |
| 41 | , {"..", ""} |
| 42 | , {"/foo", "/"} |
Eric Fiselier | 1e34c76 | 2018-04-02 23:03:41 +0000 | [diff] [blame^] | 43 | , {"foo/bar", "foo/"} |
| 44 | , {"foo/", "foo/"} |
| 45 | , {"//foo", "//"} |
| 46 | , {"//foo/", "//foo/"} |
| 47 | , {"//foo///", "//foo///"} |
| 48 | , {"///foo", "///"} |
| 49 | , {"///foo/", "///foo/"} |
| 50 | , {"/foo/", "/foo/"} |
| 51 | , {"/foo/.", "/foo/"} |
| 52 | , {"/foo/..", "/foo/"} |
| 53 | , {"/foo/////", "/foo/////"} |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 54 | , {"/foo\\\\", "/"} |
Eric Fiselier | 1e34c76 | 2018-04-02 23:03:41 +0000 | [diff] [blame^] | 55 | , {"/foo//\\/", "/foo//\\/"} |
| 56 | , {"///foo", "///"} |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 57 | , {"file.txt", ""} |
Eric Fiselier | 1e34c76 | 2018-04-02 23:03:41 +0000 | [diff] [blame^] | 58 | , {"bar/../baz/./file.txt", "bar/../baz/./"} |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | int main() |
| 62 | { |
| 63 | using namespace fs; |
| 64 | for (auto const & TC : TestCases) { |
| 65 | path const p_orig(TC.value); |
| 66 | path p(p_orig); |
| 67 | assert(p == TC.value); |
| 68 | path& Ref = (p.remove_filename()); |
Eric Fiselier | 1e34c76 | 2018-04-02 23:03:41 +0000 | [diff] [blame^] | 69 | ASSERT_EQ(p, TC.expect) << DISPLAY(p_orig); |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 70 | assert(&Ref == &p); |
Eric Fiselier | 1e34c76 | 2018-04-02 23:03:41 +0000 | [diff] [blame^] | 71 | assert(!p.has_filename()); |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 72 | } |
| 73 | } |