1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: c++03, c++11, c++14
10 // UNSUPPORTED: availability-filesystem-missing
11
12 // <filesystem>
13
14 // class path
15
16 // path& make_preferred()
17
18 #include <filesystem>
19 #include <cassert>
20 #include <string>
21 #include <type_traits>
22
23 #include "test_iterators.h"
24 #include "count_new.h"
25 namespace fs = std::filesystem;
26
27 struct MakePreferredTestcase {
28 const char* value;
29 const char* expected_posix;
30 const char* expected_windows;
31 };
32
33 const MakePreferredTestcase TestCases[] =
34 {
35 {"", "", ""}
36 , {"hello_world", "hello_world", "hello_world"}
37 , {"/", "/", "\\"}
38 , {"/foo/bar/baz/", "/foo/bar/baz/", "\\foo\\bar\\baz\\"}
39 , {"\\", "\\", "\\"}
40 , {"\\foo\\bar\\baz\\", "\\foo\\bar\\baz\\", "\\foo\\bar\\baz\\"}
41 , {"\\foo\\/bar\\/baz\\", "\\foo\\/bar\\/baz\\", "\\foo\\\\bar\\\\baz\\"}
42 };
43
main(int,char **)44 int main(int, char**)
45 {
46 // This operation is an identity operation on linux.
47 // On windows, compare with preferred_win, if set.
48 using namespace fs;
49 for (auto const & TC : TestCases) {
50 path p(TC.value);
51 assert(p == TC.value);
52 path& Ref = (p.make_preferred());
53 #ifdef _WIN32
54 std::string s(TC.expected_windows);
55 #else
56 std::string s(TC.expected_posix);
57 #endif
58 assert(p.string() == s);
59 assert(&Ref == &p);
60 }
61
62 return 0;
63 }
64