]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc
1 // { dg-do run { target c++17 } }
3 // Copyright (C) 2017-2023 Free Software Foundation, Inc.
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)
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.
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/>.
20 // C++17 30.10.7.4.7 path generic format observers [fs.path.generic.obs]
23 #include <testsuite_fs.h>
24 #include <testsuite_hooks.h>
26 using std::filesystem::path
;
31 VERIFY( path().generic_string() == "" );
32 VERIFY( path("/").generic_string() == "/" );
33 VERIFY( path("////").generic_string() == "/" );
35 VERIFY( path("//a").generic_string() == "//a" );
36 VERIFY( path("//a/").generic_string() == "//a/" );
37 VERIFY( path("//a//").generic_string() == "//a/" );
38 VERIFY( path("//a/b").generic_string() == "//a/b" );
39 VERIFY( path("//a//b").generic_string() == "//a/b" );
41 VERIFY( path("//a").generic_string() == "/a" );
42 VERIFY( path("//a/").generic_string() == "/a/" );
43 VERIFY( path("//a//").generic_string() == "/a/" );
44 VERIFY( path("//a/b").generic_string() == "/a/b" );
45 VERIFY( path("//a//b").generic_string() == "/a/b" );
47 VERIFY( path("/a//b").generic_string() == "/a/b" );
48 VERIFY( path("/a//b/").generic_string() == "/a/b/" );
49 VERIFY( path("/a//b//").generic_string() == "/a/b/" );
50 VERIFY( path("/a//b//.").generic_string() == "/a/b/." );
56 if constexpr (path::preferred_separator
== L
'\\')
59 VERIFY( path("C:\\foo\\bar").generic_string() == "C:/foo/bar" );
60 VERIFY( path("C://foo//bar").generic_string() == "C:/foo/bar" );
67 for (path p
: __gnu_test::test_paths
)
69 // A path constructed from the generic format string should compare equal
70 // to the original, because they represent the same path.
71 VERIFY( path(p
.generic_string()) == p
);
72 #ifdef _GLIBCXX_USE_WCHAR_T
73 VERIFY( path(p
.generic_wstring()) == p
);
75 VERIFY( path(p
.generic_u8string()) == p
);
76 VERIFY( path(p
.generic_u16string()) == p
);
77 VERIFY( path(p
.generic_u32string()) == p
);
80 for (path p
: { "a///b//c", "///a//b//c", "a:b//c", "a://b///c" })
82 // A path constructed from the generic format string should compare equal
83 // to the original, because they represent the same path.
84 VERIFY( path(p
.generic_string()) == p
);
85 #ifdef _GLIBCXX_USE_WCHAR_T
86 VERIFY( path(p
.generic_wstring()) == p
);
88 VERIFY( path(p
.generic_u8string()) == p
);
89 VERIFY( path(p
.generic_u16string()) == p
);
90 VERIFY( path(p
.generic_u32string()) == p
);