]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / path / append / path.cc
1 // { dg-do run { target c++17 } }
2
3 // Copyright (C) 2014-2022 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 // C++17 30.10.8.4.3 path appends [fs.path.append]
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 // path::operator/=(const path&)
30
31 path append(path l, const path& r)
32 {
33 l /= r;
34 return l;
35 }
36
37 void
38 test01()
39 {
40 compare_paths( append("/foo/bar", "/foo/"), "/foo/" );
41
42 #ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
43 compare_paths( append("baz", "baz"), "baz/baz" );
44 #else
45 compare_paths( append("baz", "baz"), "baz\\baz" );
46 #endif
47 compare_paths( append("baz/", "baz"), "baz/baz" );
48 compare_paths( append("baz", "/foo/bar"), "/foo/bar" );
49 compare_paths( append("baz/", "/foo/bar"), "/foo/bar" );
50
51 VERIFY( append("", "").empty() );
52 VERIFY( !append("", "rel").is_absolute() );
53
54 compare_paths( append("dir/", "/file"), "/file" );
55 compare_paths( append("dir/", "file"), "dir/file" );
56
57 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
58 compare_paths( append("c:/foo", "/bar"), "c:/bar" );
59 #endif
60 }
61
62 void
63 test02()
64 {
65 // C++17 [fs.path.append] p4
66 #ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
67 compare_paths( append("//host", "foo"), "//host/foo" );
68
69 compare_paths( append("//host/", "foo"), "//host/foo" );
70
71 // path("foo") / ""; // yields "foo/"
72 compare_paths( append("foo", ""), "foo/" );
73
74 // path("foo") / "/bar"; // yields "/bar"
75 compare_paths( append("foo", "/bar"), "/bar" );
76 #else
77 compare_paths( append("//host", "foo"), "//host\\foo" );
78
79 compare_paths( append("//host/", "foo"), "//host/foo" );
80
81 // path("foo") / ""; // yields "foo/"
82 compare_paths( append("foo", ""), "foo\\" );
83
84 // path("foo") / "/bar"; // yields "/bar"
85 compare_paths( append("foo", "/bar"), "/bar" );
86
87 // path("foo") / "c:/bar"; // yields "c:/bar"
88 compare_paths( append("foo", "c:/bar"), "c:/bar" );
89
90 // path("foo") / "c:"; // yields "c:"
91 compare_paths( append("foo", "c:"), "c:" );
92
93 // path("c:") / ""; // yields "c:"
94 compare_paths( append("c:", ""), "c:" );
95
96 // path("c:foo") / "/bar"; // yields "c:/bar"
97 compare_paths( append("c:foo", "/bar"), "c:/bar" );
98
99 // path("c:foo") / "c:bar"; // yields "c:foo/bar"
100 compare_paths( append("foo", "c:\\bar"), "c:\\bar" );
101 #endif
102 }
103
104 int
105 main()
106 {
107 test01();
108 test02();
109 }