| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 |
// See https://llvm.org/LICENSE.txt for license information. |
| 4 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 |
// |
| 6 |
//===----------------------------------------------------------------------===// |
| 7 |
|
| 8 |
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 9 |
|
| 10 |
// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME |
| 11 |
|
| 12 |
// <format> |
| 13 |
|
| 14 |
// template<ranges::input_range R, class charT> |
| 15 |
// struct range-default-formatter<range_format::sequence, R, charT> |
| 16 |
|
| 17 |
// template<class ParseContext> |
| 18 |
// constexpr typename ParseContext::iterator |
| 19 |
// parse(ParseContext& ctx); |
| 20 |
|
| 21 |
#include <array> |
| 22 |
#include <cassert> |
| 23 |
#include <concepts> |
| 24 |
#include <format> |
| 25 |
#include <memory> |
| 26 |
|
| 27 |
#include "test_macros.h" |
| 28 |
#include "make_string.h" |
| 29 |
|
| 30 |
#define SV(S) MAKE_STRING_VIEW(CharT, S) |
| 31 |
|
| 32 |
template <class StringViewT> |
| 33 |
constexpr void test_parse(StringViewT fmt, std::size_t offset) { |
| 34 |
using CharT = typename StringViewT::value_type; |
| 35 |
auto parse_ctx = std::basic_format_parse_context<CharT>(fmt); |
| 36 |
std::formatter<std::array<int, 2>, CharT> formatter; |
| 37 |
static_assert(std::semiregular<decltype(formatter)>); |
| 38 |
|
| 39 |
std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx); |
| 40 |
// std::to_address works around LWG3989 and MSVC STL's iterator debugging mechanism. |
| 41 |
assert(std::to_address(it) == std::to_address(fmt.end()) - offset); |
| 42 |
} |
| 43 |
|
| 44 |
template <class CharT> |
| 45 |
constexpr void test_fmt() { |
| 46 |
test_parse(SV(""), 0); |
| 47 |
test_parse(SV(":5"), 0); |
| 48 |
|
| 49 |
test_parse(SV("}"), 1); |
| 50 |
test_parse(SV(":5}"), 1); |
| 51 |
} |
| 52 |
|
| 53 |
constexpr bool test() { |
| 54 |
test_fmt<char>(); |
| 55 |
#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 56 |
test_fmt<wchar_t>(); |
| 57 |
#endif |
| 58 |
|
| 59 |
return true; |
| 60 |
} |
| 61 |
|
| 62 |
int main(int, char**) { |
| 63 |
test(); |
| 64 |
static_assert(test()); |
| 65 |
|
| 66 |
return 0; |
| 67 |
} |