1 // Copyright (C) 2017 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
;
27 using __gnu_test::compare_paths
;
32 // C++17 [fs.path.gen] p2
33 compare_paths( path("foo/./bar/..").lexically_normal(), "foo/" );
34 compare_paths( path("foo/.///bar/../").lexically_normal(), "foo/" );
40 compare_paths( path("foo/../bar").lexically_normal(), "bar" );
41 compare_paths( path("../foo/../bar").lexically_normal(), "../bar" );
42 compare_paths( path("foo/../").lexically_normal(), "." );
43 compare_paths( path("../../").lexically_normal(), "../.." );
44 compare_paths( path("../").lexically_normal(), ".." );
45 compare_paths( path("./").lexically_normal(), "." );
46 compare_paths( path().lexically_normal(), "" );
48 compare_paths( path("/..").lexically_normal(), "/" );
51 compare_paths( path("./a/b/c/../.././b/c").lexically_normal(), "a/b/c" );
52 compare_paths( path("/a/b/c/../.././b/c").lexically_normal(), "/a/b/c" );
61 const char* normalized
;
71 {"/foo/." , "/foo/" },
72 {"/foo/bar/.." , "/foo/" },
90 {"foo/../.." , ".." },
92 // with root name (OS-dependent):
93 #if defined(_WIN32) && !defined(__CYGWIN__)
94 {"C:bar/.." , "C:." },
98 {"C:/bar/.." , "C:/" },
101 {"//host/bar/.." , "//host/" },
102 {"//host" , "//host" },
104 {"//host/bar/.." , "/host/" },
105 {"//host" , "/host" },
109 {"foo/../foo/.." , "." },
110 {"foo/../foo/../.." , ".." },
111 {"../foo/../foo/.." , ".." },
112 {"../.f/../f" , "../f" },
113 {"../f/../.f" , "../.f" },
114 {".././../." , "../.." },
115 {".././.././" , "../.." },
118 for (auto& test
: testcases
)
119 compare_paths( path(test
.input
).lexically_normal(), test
.normalized
);