fortran: Correctly evaluate scalar MASK arguments of MINLOC/MAXLOC
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / path / decompose / parent_path.cc
blobfd55be82dbca639441574e3dfe405f63046da9bc
1 // { dg-do run { target c++17 } }
3 // Copyright (C) 2014-2024 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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]
22 #include <filesystem>
23 #include <testsuite_hooks.h>
24 #include <testsuite_fs.h>
26 using std::filesystem::path;
28 void
29 test01()
31 path p0;
32 VERIFY( p0.parent_path() == p0 );
33 path p1 = "foo";
34 VERIFY( p1.parent_path() == p0 );
35 path p2 = "foo/bar";
36 VERIFY( p2.parent_path() == p1 );
37 path p3 = "/foo/bar";
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("/") );
41 path p4 = "/";
42 VERIFY( p4.parent_path() == p4 );
45 void
46 test02()
48 for (const path p : __gnu_test::test_paths)
50 if (p.begin() == p.end())
51 continue;
52 if (p.has_relative_path())
54 path pp;
55 for (auto i = p.begin(), end = --p.end(); i != end; ++i)
57 pp /= *i;
59 VERIFY( p.parent_path() == pp );
61 else
62 VERIFY( p.parent_path() == p );
66 void
67 test03()
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/..."
74 // PR libstdc++/99805
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 );
81 path from_lval(s);
82 pp = from_lval.parent_path();
83 VERIFY( pp.native() == s1 );
84 pp = pp.parent_path().parent_path();
85 VERIFY( pp.native() == s2 );
88 int
89 main()
91 test01();
92 test02();
93 test03();