]> 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-options "-std=gnu++17 -lstdc++fs" }
2 // { dg-do run { target c++17 } }
3 // { dg-require-filesystem-ts "" }
4
5 // Copyright (C) 2014-2019 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.
12
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.
17
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/>.
21
22 // C++17 30.10.8.4.3 path appends [fs.path.append]
23
24 #include <filesystem>
25 #include <testsuite_hooks.h>
26 #include <testsuite_fs.h>
27
28 using std::filesystem::path;
29 using __gnu_test::compare_paths;
30
31 // path::operator/=(const path&)
32
33 path append(path l, const path& r)
34 {
35 l /= r;
36 return l;
37 }
38
39 void
40 test01()
41 {
42 compare_paths( append("/foo/bar", "/foo/"), "/foo/" );
43
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" );
52
53 VERIFY( append("", "").empty() );
54 VERIFY( !append("", "rel").is_absolute() );
55
56 compare_paths( append("dir/", "/file"), "/file" );
57 compare_paths( append("dir/", "file"), "dir/file" );
58
59 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
60 compare_paths( append("c:/foo", "/bar"), "c:/bar" );
61 #endif
62 }
63
64 void
65 test02()
66 {
67 // C++17 [fs.path.append] p4
68 #ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
69 compare_paths( append("//host", "foo"), "//host/foo" );
70
71 compare_paths( append("//host/", "foo"), "//host/foo" );
72
73 // path("foo") / ""; // yields "foo/"
74 compare_paths( append("foo", ""), "foo/" );
75
76 // path("foo") / "/bar"; // yields "/bar"
77 compare_paths( append("foo", "/bar"), "/bar" );
78 #else
79 compare_paths( append("//host", "foo"), "//host\\foo" );
80
81 compare_paths( append("//host/", "foo"), "//host/foo" );
82
83 // path("foo") / ""; // yields "foo/"
84 compare_paths( append("foo", ""), "foo\\" );
85
86 // path("foo") / "/bar"; // yields "/bar"
87 compare_paths( append("foo", "/bar"), "/bar" );
88
89 // path("foo") / "c:/bar"; // yields "c:/bar"
90 compare_paths( append("foo", "c:/bar"), "c:/bar" );
91
92 // path("foo") / "c:"; // yields "c:"
93 compare_paths( append("foo", "c:"), "c:" );
94
95 // path("c:") / ""; // yields "c:"
96 compare_paths( append("c:", ""), "c:" );
97
98 // path("c:foo") / "/bar"; // yields "c:/bar"
99 compare_paths( append("c:foo", "/bar"), "c:/bar" );
100
101 // path("c:foo") / "c:bar"; // yields "c:foo/bar"
102 compare_paths( append("foo", "c:\\bar"), "c:\\bar" );
103 #endif
104 }
105
106 int
107 main()
108 {
109 test01();
110 test02();
111 }