PR libstdc++/84159 fix appending strings to paths
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / path / append / path.cc
blob0330bcf6c88ccb40e50ff2bc151dd996613a34c3
1 // { dg-options "-std=gnu++17 -lstdc++fs" }
2 // { dg-do run { target c++17 } }
3 // { dg-require-filesystem-ts "" }
5 // Copyright (C) 2014-2018 Free Software Foundation, Inc.
6 //
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)
11 // any later version.
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]
24 #include <filesystem>
25 #include <testsuite_hooks.h>
26 #include <testsuite_fs.h>
28 using std::filesystem::path;
29 using __gnu_test::compare_paths;
31 // path::operator/=(const path&)
33 path append(path l, const path& r)
35 l /= r;
36 return l;
39 void
40 test01()
42 compare_paths( append("/foo/bar", "/foo/"), "/foo/" );
44 #ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
45 compare_paths( append("baz", "baz"), "baz/baz" );
46 #else
47 compare_paths( append("baz", "baz"), "baz\\baz" );
48 #endif
49 compare_paths( append("baz/", "baz"), "baz/baz" );
50 compare_paths( append("baz", "/foo/bar"), "/foo/bar" );
51 compare_paths( append("baz/", "/foo/bar"), "/foo/bar" );
53 VERIFY( append("", "").empty() );
54 VERIFY( !append("", "rel").is_absolute() );
56 compare_paths( append("dir/", "/file"), "/file" );
57 compare_paths( append("dir/", "file"), "dir/file" );
60 void
61 test02()
63 // C++17 [fs.path.append] p4
64 #ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
65 compare_paths( append("//host", "foo"), "//host/foo" );
67 compare_paths( append("//host/", "foo"), "//host/foo" );
69 // path("foo") / ""; // yields "foo/"
70 compare_paths( append("foo", ""), "foo/" );
72 // path("foo") / "/bar"; // yields "/bar"
73 compare_paths( append("foo", "/bar"), "/bar" );
74 #else
75 compare_paths( append("//host", "foo"), "//host\\foo" );
77 compare_paths( append("//host/", "foo"), "//host/foo" );
79 // path("foo") / ""; // yields "foo/"
80 compare_paths( append("foo", ""), "foo\\" );
82 // path("foo") / "/bar"; // yields "/bar"
83 compare_paths( append("foo", "/bar"), "/bar" );
85 // path("foo") / "c:/bar"; // yields "c:/bar"
86 compare_paths( append("foo", "c:/bar"), "c:/bar" );
88 // path("foo") / "c:"; // yields "c:"
89 compare_paths( append("foo", "c:"), "c:" );
91 // path("c:") / ""; // yields "c:"
92 compare_paths( append("c:", ""), "c:" );
94 // path("c:foo") / "/bar"; // yields "c:/bar"
95 compare_paths( append("c:foo", "/bar"), "c:/bar" );
97 // path("c:foo") / "c:bar"; // yields "c:foo/bar"
98 compare_paths( append("foo", "c:\\bar"), "c:\\bar" );
99 #endif
103 main()
105 test01();
106 test02();