1 // { dg-do run { target c++17 } }
3 // Copyright (C) 2014-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // C++17 30.10.8.4.9 path decomposition [fs.path.decompose]
23 #include <testsuite_hooks.h>
24 #include <testsuite_fs.h>
26 using std::filesystem::path
;
32 VERIFY( p0
.parent_path() == p0
);
34 VERIFY( p1
.parent_path() == p0
);
36 VERIFY( p2
.parent_path() == p1
);
38 VERIFY( p3
.parent_path() == path("/foo") );
39 VERIFY( p3
.parent_path().parent_path() == path("/") );
40 VERIFY( p3
.parent_path().parent_path().parent_path() == path("/") );
42 VERIFY( p4
.parent_path() == p4
);
48 for (const path p
: __gnu_test::test_paths
)
50 if (p
.begin() == p
.end())
52 if (p
.has_relative_path())
55 for (auto i
= p
.begin(), end
= --p
.end(); i
!= end
; ++i
)
59 VERIFY( p
.parent_path() == pp
);
62 VERIFY( p
.parent_path() == p
);
69 const std::string narrow
= "there/are/no/wrong/turns/only/unexpected/paths";
70 const path::string_type
s(narrow
.begin(), narrow
.end());
71 const auto s1
= s
.substr(0, s
.length() - 6); // remove "/paths"
72 const auto s2
= s1
.substr(0, s1
.length() - 16); // remove "/only/..."
75 path p
= path::string_type(s
);
76 auto pp
= p
.parent_path();
77 VERIFY( pp
.native() == s1
);
78 pp
= pp
.parent_path().parent_path();
79 VERIFY( pp
.native() == s2
);
82 pp
= from_lval
.parent_path();
83 VERIFY( pp
.native() == s1
);
84 pp
= pp
.parent_path().parent_path();
85 VERIFY( pp
.native() == s2
);