| 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 | // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS |
| 11 | // UNSUPPORTED: availability-filesystem-missing |
| 12 | |
| 13 | // <filesystem> |
| 14 | |
| 15 | // template <class Source> |
| 16 | // path u8path(Source const&); |
| 17 | // template <class InputIter> |
| 18 | // path u8path(InputIter, InputIter); |
| 19 | |
| 20 | #include <filesystem> |
| 21 | #include <cassert> |
| 22 | #include <string> |
| 23 | #include <type_traits> |
| 24 | |
| 25 | #include "test_macros.h" |
| 26 | #include "test_iterators.h" |
| 27 | #include "count_new.h" |
| 28 | namespace fs = std::filesystem; |
| 29 | |
| 30 | int main(int, char**) |
| 31 | { |
| 32 | using namespace fs; |
| 33 | const char* In1 = "abcd/efg" ; |
| 34 | const std::string In2(In1); |
| 35 | const auto In3 = In2.begin(); |
| 36 | const auto In3End = In2.end(); |
| 37 | { |
| 38 | path p = fs::u8path(source: In1); |
| 39 | assert(p == In1); |
| 40 | } |
| 41 | { |
| 42 | path p = fs::u8path(source: In2); |
| 43 | assert(p == In1); |
| 44 | } |
| 45 | { |
| 46 | path p = fs::u8path(source: In2.data()); |
| 47 | assert(p == In1); |
| 48 | } |
| 49 | { |
| 50 | path p = fs::u8path(first: In3, last: In3End); |
| 51 | assert(p == In1); |
| 52 | } |
| 53 | #if TEST_STD_VER > 17 && defined(__cpp_char8_t) && defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_LOCALIZATION) |
| 54 | const char8_t* u8In1 = u8"abcd/efg" ; |
| 55 | const std::u8string u8In2(u8In1); |
| 56 | const auto u8In3 = u8In2.begin(); |
| 57 | const auto u8In3End = u8In2.end(); |
| 58 | // Proposed in P1423, marked tested only for libc++ |
| 59 | { |
| 60 | path p = fs::u8path(u8In1); |
| 61 | assert(p == In1); |
| 62 | } |
| 63 | { |
| 64 | path p = fs::u8path(u8In2); |
| 65 | assert(p == In1); |
| 66 | } |
| 67 | { |
| 68 | path p = fs::u8path(u8In2.data()); |
| 69 | assert(p == In1); |
| 70 | } |
| 71 | { |
| 72 | path p = fs::u8path(u8In3, u8In3End); |
| 73 | assert(p == In1); |
| 74 | } |
| 75 | #endif |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |