]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc
3891a9bb7c2e5a416edbb2fd62b677840f6ee33e
1 // { dg-do run { target c++17 } }
3 // Copyright (C) 2018-2021 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.3 path appends [fs.path.append]
23 #include <string_view>
24 #include <testsuite_fs.h>
25 #include <testsuite_iterators.h>
27 using std::filesystem::path
;
28 using __gnu_test::compare_paths
;
30 // path::operator/=(const Source& source)
31 // path::append(const Source& source)
32 // Equivalent to: return operator/=(path(source));
34 // path::append(InputIterator first, InputIterator last)
35 // Equivalent to: return operator/=(path(first, last));
37 template<typename Char
>
38 void test(const path
& p
, const Char
* s
)
49 __gnu_test::test_container
<const Char
, __gnu_test::input_iterator_wrapper
>
50 input_range(s
, s
+ std::char_traits
<Char
>::length(s
));
52 range
.append(input_range
.begin(), input_range
.end());
54 compare_paths( oper
, expected
);
55 compare_paths( func
, expected
);
56 compare_paths( range
, expected
);
62 test( "/foo/bar", "/foo/" );
65 test( "baz/", "baz" );
66 test( "baz", "/foo/bar" );
67 test( "baz/", "/foo/bar" );
72 test( "dir/", "/file" );
73 test( "dir/", "file" );
79 // C++17 [fs.path.append] p4
80 test( "//host", "foo" );
81 test( "//host/", "foo" );
83 test( "foo", "/bar" );
84 test( "foo", "c:/bar" );
87 test( "c:foo", "/bar" );
88 test( "foo", "c:\\bar" );
94 for (const path p
: __gnu_test::test_paths
)
95 for (const path q
: __gnu_test::test_paths
)
98 if constexpr (!std::is_same_v
<path::value_type
, char>)
99 test(p
, q
.string().c_str());
106 #ifdef _GLIBCXX_USE_WCHAR_T
107 test( "foo", L
"/bar" );
108 test( L
"foo", "/bar" );
109 test( L
"foo", L
"/bar" );
116 std::basic_string_view
<path::value_type
> s
;
118 path p
= "0/1/2/3/4/5/6";
119 // The string_view aliases the path's internal string:
121 path::string_type
expected(s
);
122 expected
+= path::preferred_separator
;
124 // Append that string_view, which must work correctly even though the
125 // internal string will be reallocated during the operation:
127 compare_paths(p
, expected
);
129 // Same again with a trailing slash:
130 path p2
= "0/1/2/3/4/5/";
135 compare_paths(p2
, expected
);
137 // And aliasing one of the components of the path:
138 path p3
= "0/123456789/a";
139 path::iterator second
= std::next(p3
.begin());
140 s
= second
->native();
141 expected
= p3
.native() + path::preferred_separator
;
144 compare_paths(p3
, expected
);
150 const std::string s0
= "a/b/c";
153 for (int i
= 0; i
< 10; ++i
)
154 s
+= "0/1/2/3/4/5/6/7/8/9/";
155 // append a long string with many components
158 // Same again but with a trailing slash on the left operand:
168 p
/= s
; // PR libstdc++/97167
169 compare_paths(p
, p0
);