]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc
1 // Copyright (C) 2017-2019 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++17 -lstdc++fs" }
19 // { dg-do run { target c++17 } }
20 // { dg-require-filesystem-ts "" }
23 #include <testsuite_fs.h>
24 #include <testsuite_hooks.h>
26 using std::filesystem::path
;
29 compare_paths(path p
, std::string expected
)
31 #if defined(_WIN32) && !defined(__CYGWIN__)
32 for (auto& c
: expected
)
36 __gnu_test::compare_paths(p
, expected
);
42 // C++17 [fs.path.gen] p2
43 compare_paths( path("foo/./bar/..").lexically_normal(), "foo/" );
44 compare_paths( path("foo/.///bar/../").lexically_normal(), "foo/" );
50 compare_paths( path("foo/../bar").lexically_normal(), "bar" );
51 compare_paths( path("../foo/../bar").lexically_normal(), "../bar" );
52 compare_paths( path("foo/../").lexically_normal(), "." );
53 compare_paths( path("../../").lexically_normal(), "../.." );
54 compare_paths( path("../").lexically_normal(), ".." );
55 compare_paths( path("./").lexically_normal(), "." );
56 compare_paths( path().lexically_normal(), "" );
58 compare_paths( path("/..").lexically_normal(), "/" );
61 compare_paths( path("./a/b/c/../.././b/c").lexically_normal(), "a/b/c" );
62 compare_paths( path("/a/b/c/../.././b/c").lexically_normal(), "/a/b/c" );
71 const char* normalized
;
81 {"/foo/." , "/foo/" },
83 {"/foo/../.." , "/" },
84 {"/foo/bar/.." , "/foo/" },
85 {"/foo/bar/../.." , "/" },
86 {"/foo/bar/baz/../../.." , "/" }, // PR libstdc++/87116
103 {"foo/../.." , ".." },
104 {"foo/../../..", "../.." },
106 // with root name (OS-dependent):
107 #if defined(_WIN32) && !defined(__CYGWIN__)
108 {"C:bar/.." , "C:" },
112 {"C:/bar/.." , "C:/" },
115 {"//host/bar/.." , "//host/" },
116 {"//host" , "//host" },
118 {"//host/bar/.." , "/host/" },
119 {"//host" , "/host" },
123 {"foo/../foo/.." , "." },
124 {"foo/../foo/../.." , ".." },
125 {"../foo/../foo/.." , ".." },
126 {"../.f/../f" , "../f" },
127 {"../f/../.f" , "../.f" },
128 {".././../." , "../.." },
129 {".././.././" , "../.." },
132 for (auto& test
: testcases
)
133 compare_paths( path(test
.input
).lexically_normal(), test
.normalized
);
139 // PR libstdc++/87116
141 compare_paths( (p
/"../..").lexically_normal(), "a/" );
144 compare_paths( (p
/"..").lexically_normal(), "a/b/c/d/" );
145 compare_paths( (p
/"../..").lexically_normal(), "a/b/c/" );
146 compare_paths( (p
/"../../..").lexically_normal(), "a/b/" );
147 compare_paths( (p
/"../../../..").lexically_normal(), "a/" );
148 compare_paths( (p
/"../../../../..").lexically_normal(), "." );
149 compare_paths( (p
/"../../../../../..").lexically_normal(), ".." );
152 compare_paths( (p
/"..").lexically_normal(), "/a/b/c/d/" );
153 compare_paths( (p
/"../..").lexically_normal(), "/a/b/c/" );
154 compare_paths( (p
/"../../..").lexically_normal(), "/a/b/" );
155 compare_paths( (p
/"../../../..").lexically_normal(), "/a/" );
156 compare_paths( (p
/"../../../../..").lexically_normal(), "/" );
157 compare_paths( (p
/"../../../../../..").lexically_normal(), "/" );
159 #if defined(_WIN32) && !defined(__CYGWIN__)
161 compare_paths( (p
/"..").lexically_normal(), "A:b/c/d/" );
162 compare_paths( (p
/"../..").lexically_normal(), "A:b/c/" );
163 compare_paths( (p
/"../../..").lexically_normal(), "A:b/" );
164 compare_paths( (p
/"../../../..").lexically_normal(), "A:" );
165 compare_paths( (p
/"../../../../..").lexically_normal(), "A:.." );
166 compare_paths( (p
/"../../../../../..").lexically_normal(), "A:../.." );
169 compare_paths( (p
/"..").lexically_normal(), "A:/b/c/d/" );
170 compare_paths( (p
/"../..").lexically_normal(), "A:/b/c/" );
171 compare_paths( (p
/"../../..").lexically_normal(), "A:/b/" );
172 compare_paths( (p
/"../../../..").lexically_normal(), "A:/" );
173 compare_paths( (p
/"../../../../..").lexically_normal(), "A:/" );
174 compare_paths( (p
/"../../../../../..").lexically_normal(), "A:/" );