]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc
1 // { dg-do run { target c++17 } }
3 // Copyright (C) 2014-2022 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.7.5 path iterators [fs.path.itr]
25 #include <testsuite_hooks.h>
26 #include <testsuite_fs.h>
28 using std::filesystem::path
;
34 VERIFY( p
.begin() == p
.end() );
36 std::vector
<path
> v
, v2
;
39 v
.assign(p
.begin(), p
.end());
44 v
.assign(p
.begin(), p
.end());
49 v
.assign(p
.begin(), p
.end());
54 v
.assign(p
.begin(), p
.end());
58 p
= "//rootname/dir/.";
59 v
.assign(p
.begin(), p
.end());
61 v2
= { "//rootname", "/", "dir", "." };
63 v2
= { "/", "rootname", "dir", "." };
67 p
= "//rootname/dir/";
68 v
.assign(p
.begin(), p
.end());
70 v2
= { "//rootname", "/", "dir", "" };
72 v2
= { "/", "rootname", "dir", "" };
76 p
= "//rootname/dir/filename";
77 v
.assign(p
.begin(), p
.end());
79 v2
= { "//rootname", "/", "dir", "filename" };
81 v2
= { "/", "rootname", "dir", "filename" };
85 p
= "c:relative/path";
86 v
.assign(p
.begin(), p
.end());
87 #if defined(__MINGW32__) || defined(__MINGW64__)
88 v2
= { "c:", "relative", "path" };
90 v2
= { "c:relative", "path" };
94 p
= "c:/absolute/path";
95 v
.assign(p
.begin(), p
.end());
96 #if defined(__MINGW32__) || defined(__MINGW64__)
97 v2
= { "c:", "/", "absolute", "path" };
99 v2
= { "c:", "absolute", "path" };
107 using reverse_iterator
= std::reverse_iterator
<path::iterator
>;
108 std::vector
<path
> fwd
, rev
;
110 for (const path p
: __gnu_test::test_paths
)
112 const auto begin
= p
.begin(), end
= p
.end();
113 fwd
.assign(begin
, end
);
114 rev
.assign(reverse_iterator(end
), reverse_iterator(begin
));
115 VERIFY( fwd
.size() == rev
.size() );
116 VERIFY( std::equal(fwd
.begin(), fwd
.end(), rev
.rbegin()) );
123 path paths
[] = { "single", "multiple/elements", "trailing/slash/", "/." };
124 for (const path
& p
: paths
)
125 for (auto iter
= p
.begin(); iter
!= p
.end(); ++iter
)
130 VERIFY( iter2
== iter
);
133 VERIFY( iter2
== iter
);
140 std::filesystem::path p
= "/a/b/c/d/e/f/g";
141 VERIFY( std::distance(p
.begin(), p
.end()) == 8);
144 VERIFY( std::distance(p
.begin(), it
) == 1 );
145 VERIFY( it
->string() == "a" );
147 VERIFY( std::distance(p
.begin(), it
) == 4 );
148 VERIFY( it
->string() == "d" );
149 std::advance(it
, -2);
150 VERIFY( std::distance(p
.begin(), it
) == 2 );
151 VERIFY( it
->string() == "b" );