| 1 |
// { dg-do run { target c++17 } } |
| 2 |
|
| 3 |
// Copyright (C) 2014-2025 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. |
| 10 |
|
| 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. |
| 15 |
|
| 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/>. |
| 19 |
|
| 20 |
// 30.10.7.4.4 path concatenation [fs.path.concat] |
| 21 |
|
| 22 |
#include <filesystem> |
| 23 |
#include <testsuite_hooks.h> |
| 24 |
#include <testsuite_fs.h> |
| 25 |
|
| 26 |
using std::filesystem::path; |
| 27 |
using __gnu_test::compare_paths; |
| 28 |
|
| 29 |
void |
| 30 |
test01() |
| 31 |
{ |
| 32 |
const path p("/foo/bar"); |
| 33 |
|
| 34 |
path pp = p; |
| 35 |
pp += p; |
| 36 |
compare_paths( pp, "/foo/bar/foo/bar" ); |
| 37 |
|
| 38 |
path q("foo/bar"); |
| 39 |
|
| 40 |
path qq = q; |
| 41 |
qq += q; |
| 42 |
compare_paths( qq, "foo/barfoo/bar" ); |
| 43 |
|
| 44 |
q += p; |
| 45 |
compare_paths( q, "foo/bar/foo/bar" ); |
| 46 |
} |
| 47 |
|
| 48 |
void |
| 49 |
test02() |
| 50 |
{ |
| 51 |
for (path p : __gnu_test::test_paths) |
| 52 |
{ |
| 53 |
auto prior_native = p.native(); |
| 54 |
path x("//blah/di/blah"); |
| 55 |
p += x; |
| 56 |
VERIFY( p.native() == prior_native + x.native() ); |
| 57 |
path copy(p); |
| 58 |
compare_paths( copy, p ); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
void |
| 63 |
test03() |
| 64 |
{ |
| 65 |
path p = "a/"; |
| 66 |
p += path("/b"); |
| 67 |
compare_paths(p, "a//b"); |
| 68 |
} |
| 69 |
|
| 70 |
void |
| 71 |
test04() |
| 72 |
{ |
| 73 |
// Concat every test path onto every test path. |
| 74 |
for (path p : __gnu_test::test_paths) |
| 75 |
{ |
| 76 |
for (path x : __gnu_test::test_paths) |
| 77 |
{ |
| 78 |
auto prior_native = p.native(); |
| 79 |
p += x; |
| 80 |
VERIFY( p.native() == prior_native + x.native() ); |
| 81 |
path copy(p); // PR libstdc++/98523 |
| 82 |
compare_paths( copy, p ); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
int |
| 88 |
main() |
| 89 |
{ |
| 90 |
test01(); |
| 91 |
test02(); |
| 92 |
test03(); |
| 93 |
test04(); |
| 94 |
} |