]>
Commit | Line | Data |
---|---|---|
85ec4feb | 1 | // Copyright (C) 2017-2018 Free Software Foundation, Inc. |
641cb5a6 JW |
2 | // |
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) | |
7 | // any later version. | |
8 | ||
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. | |
13 | ||
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/>. | |
17 | ||
18 | // { dg-options "-std=gnu++17 -lstdc++fs" } | |
19 | // { dg-do run { target c++17 } } | |
20 | // { dg-require-filesystem-ts "" } | |
21 | ||
22 | #include <filesystem> | |
eeb517d3 | 23 | #include <testsuite_fs.h> |
641cb5a6 JW |
24 | #include <testsuite_hooks.h> |
25 | ||
26 | using std::filesystem::path; | |
eeb517d3 | 27 | using __gnu_test::compare_paths; |
641cb5a6 JW |
28 | |
29 | void | |
30 | test01() | |
31 | { | |
32 | // C++17 [fs.path.gen] p2 | |
eeb517d3 JW |
33 | compare_paths( path("foo/./bar/..").lexically_normal(), "foo/" ); |
34 | compare_paths( path("foo/.///bar/../").lexically_normal(), "foo/" ); | |
641cb5a6 JW |
35 | } |
36 | ||
37 | void | |
38 | test02() | |
39 | { | |
eeb517d3 JW |
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(), "" ); | |
47 | ||
48 | compare_paths( path("/..").lexically_normal(), "/" ); | |
50e248f0 JW |
49 | |
50 | // PR libstdc++/82777 | |
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" ); | |
eeb517d3 JW |
53 | } |
54 | ||
55 | void | |
56 | test03() | |
57 | { | |
58 | struct | |
59 | { | |
60 | const char* input; | |
61 | const char* normalized; | |
62 | } testcases[] = { | |
63 | {"" , "" }, | |
64 | {"." , "." }, | |
65 | {".." , ".." }, | |
66 | {"/" , "/" }, | |
67 | {"//" , "//" }, | |
68 | ||
69 | {"/foo" , "/foo" }, | |
70 | {"/foo/" , "/foo/" }, | |
71 | {"/foo/." , "/foo/" }, | |
72 | {"/foo/bar/.." , "/foo/" }, | |
73 | {"/foo/.." , "/" }, | |
74 | ||
75 | {"/." , "/" }, | |
76 | {"/./" , "/" }, | |
77 | {"/./." , "/" }, | |
78 | {"/././" , "/" }, | |
79 | {"/././." , "/" }, | |
80 | ||
81 | {"./" , "." }, | |
82 | {"./." , "." }, | |
83 | {"././" , "." }, | |
84 | {"././." , "." }, | |
85 | {"./././" , "." }, | |
86 | {"./././." , "." }, | |
87 | ||
88 | {"foo/.." , "." }, | |
89 | {"foo/../" , "." }, | |
90 | {"foo/../.." , ".." }, | |
91 | ||
92 | // with root name (OS-dependent): | |
93 | #if defined(_WIN32) && !defined(__CYGWIN__) | |
94 | {"C:bar/.." , "C:." }, | |
95 | #else | |
96 | {"C:bar/.." , "." }, | |
97 | #endif | |
98 | {"C:/bar/.." , "C:/" }, | |
99 | {"C:" , "C:" }, | |
100 | #ifdef __CYGWIN__ | |
101 | {"//host/bar/.." , "//host/" }, | |
102 | {"//host" , "//host" }, | |
103 | #else | |
104 | {"//host/bar/.." , "/host/" }, | |
105 | {"//host" , "/host" }, | |
106 | #endif | |
107 | ||
108 | // a few others: | |
109 | {"foo/../foo/.." , "." }, | |
110 | {"foo/../foo/../.." , ".." }, | |
111 | {"../foo/../foo/.." , ".." }, | |
112 | {"../.f/../f" , "../f" }, | |
113 | {"../f/../.f" , "../.f" }, | |
114 | {".././../." , "../.." }, | |
115 | {".././.././" , "../.." }, | |
116 | {"/.." , "/" }, | |
117 | }; | |
118 | for (auto& test : testcases) | |
119 | compare_paths( path(test.input).lexically_normal(), test.normalized ); | |
641cb5a6 JW |
120 | } |
121 | ||
122 | int | |
123 | main() | |
124 | { | |
125 | test01(); | |
126 | test02(); | |
eeb517d3 | 127 | test03(); |
641cb5a6 | 128 | } |