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
10 
11 // <filesystem>
12 
13 // class path
14 
15 // path& remove_filename()
16 
17 #include "filesystem_include.h"
18 #include <type_traits>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 #include "test_iterators.h"
23 #include "count_new.h"
24 #include "filesystem_test_helper.h"
25 
26 struct RemoveFilenameTestcase {
27   const char* value;
28   const char* expect;
29 };
30 
31 const RemoveFilenameTestcase TestCases[] =
32   {
33       {"", ""}
34     , {"/", "/"}
35     , {"//", "//"}
36     , {"///", "///"}
37     , {"\\", ""}
38     , {".", ""}
39     , {"..", ""}
40     , {"/foo", "/"}
41     , {"foo/bar", "foo/"}
42     , {"foo/", "foo/"}
43     , {"//foo", "//"}
44     , {"//foo/", "//foo/"}
45     , {"//foo///", "//foo///"}
46     , {"///foo", "///"}
47     , {"///foo/", "///foo/"}
48     , {"/foo/", "/foo/"}
49     , {"/foo/.", "/foo/"}
50     , {"/foo/..", "/foo/"}
51     , {"/foo/////", "/foo/////"}
52     , {"/foo\\\\", "/"}
53     , {"/foo//\\/", "/foo//\\/"}
54     , {"///foo", "///"}
55     , {"file.txt", ""}
56     , {"bar/../baz/./file.txt", "bar/../baz/./"}
57   };
58 
59 int main(int, char**)
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     assert(!p.has_filename());
70   }
71 
72   return 0;
73 }
74