]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc
1 // { dg-options "-std=gnu++17 -lstdc++fs" }
2 // { dg-do run { target c++17 } }
3 // { dg-require-filesystem-ts "" }
5 // Copyright (C) 2018-2019 Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 // C++17 30.10.8.4.3 path appends [fs.path.append]
25 #include <string_view>
26 #include <testsuite_fs.h>
27 #include <testsuite_iterators.h>
29 using std::filesystem::path
;
30 using __gnu_test::compare_paths
;
32 // path::operator/=(const Source& source)
33 // path::append(const Source& source)
34 // Equivalent to: return operator/=(path(source));
36 // path::append(InputIterator first, InputIterator last)
37 // Equivalent to: return operator/=(path(first, last));
39 template<typename Char
>
40 void test(const path
& p
, const Char
* s
)
51 __gnu_test::test_container
<const Char
, __gnu_test::input_iterator_wrapper
>
52 input_range(s
, s
+ std::char_traits
<Char
>::length(s
));
54 range
.append(input_range
.begin(), input_range
.end());
56 compare_paths( oper
, expected
);
57 compare_paths( func
, expected
);
58 compare_paths( range
, expected
);
64 test( "/foo/bar", "/foo/" );
67 test( "baz/", "baz" );
68 test( "baz", "/foo/bar" );
69 test( "baz/", "/foo/bar" );
74 test( "dir/", "/file" );
75 test( "dir/", "file" );
81 // C++17 [fs.path.append] p4
82 test( "//host", "foo" );
83 test( "//host/", "foo" );
85 test( "foo", "/bar" );
86 test( "foo", "c:/bar" );
89 test( "c:foo", "/bar" );
90 test( "foo", "c:\\bar" );
96 for (const path
& p
: __gnu_test::test_paths
)
97 for (const path
& q
: __gnu_test::test_paths
)
100 if constexpr (!std::is_same_v
<path::value_type
, char>)
101 test(p
, q
.string().c_str());
108 #ifdef _GLIBCXX_USE_WCHAR_T
109 test( "foo", L
"/bar" );
110 test( L
"foo", "/bar" );
111 test( L
"foo", L
"/bar" );
118 std::basic_string_view
<path::value_type
> s
;
120 path p
= "0/1/2/3/4/5/6";
121 // The string_view aliases the path's internal string:
123 path::string_type
expected(s
);
124 expected
+= path::preferred_separator
;
126 // Append that string_view, which must work correctly even though the
127 // internal string will be reallocated during the operation:
129 compare_paths(p
, expected
);
131 // Same again with a trailing slash:
132 path p2
= "0/1/2/3/4/5/";
137 compare_paths(p2
, expected
);
139 // And aliasing one of the components of the path:
140 path p3
= "0/123456789/a";
141 path::iterator second
= std::next(p3
.begin());
142 s
= second
->native();
143 expected
= p3
.native() + path::preferred_separator
;
146 compare_paths(p3
, expected
);
152 const std::string s0
= "a/b/c";
155 for (int i
= 0; i
< 10; ++i
)
156 s
+= "0/1/2/3/4/5/6/7/8/9/";
157 // append a long string with many components
160 // Same again but with a trailing slash on the left operand: