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 | // <format> |
11 | |
12 | // template<ranges::input_range R, class charT> |
13 | // requires (K == range_format::string || K == range_format::debug_string) |
14 | // struct range-default-formatter<K, R, charT> |
15 | |
16 | // template<class ParseContext> |
17 | // constexpr typename ParseContext::iterator |
18 | // parse(ParseContext& ctx); |
19 | |
20 | // Note this tests the basics of this function. It's tested in more detail in |
21 | // the format.functions test. |
22 | |
23 | #include <cassert> |
24 | #include <concepts> |
25 | #include <format> |
26 | #include <memory> |
27 | |
28 | #include "format.functions.tests.h" |
29 | #include "test_macros.h" |
30 | |
31 | template <class FormatterT, class StringViewT> |
32 | constexpr void test_parse(StringViewT fmt, std::size_t offset) { |
33 | using CharT = typename StringViewT::value_type; |
34 | auto parse_ctx = std::basic_format_parse_context<CharT>(fmt); |
35 | FormatterT formatter; |
36 | static_assert(std::semiregular<decltype(formatter)>); |
37 | |
38 | std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx); |
39 | // std::to_address works around LWG3989 and MSVC STL's iterator debugging mechanism. |
40 | assert(std::to_address(it) == std::to_address(fmt.end()) - offset); |
41 | } |
42 | |
43 | template <class StringViewT> |
44 | constexpr void test_formatters(StringViewT fmt, std::size_t offset) { |
45 | using CharT = typename StringViewT::value_type; |
46 | test_parse<std::formatter<test_range_format_string<std::basic_string<CharT>>, CharT>>(fmt, offset); |
47 | test_parse<std::formatter<test_range_format_debug_string<std::basic_string<CharT>>, CharT>>(fmt, offset); |
48 | } |
49 | |
50 | template <class CharT> |
51 | constexpr void test_char_type() { |
52 | test_formatters(SV("" ), 0); |
53 | test_formatters(SV("}" ), 1); |
54 | } |
55 | |
56 | constexpr bool test() { |
57 | test_char_type<char>(); |
58 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
59 | test_char_type<wchar_t>(); |
60 | #endif |
61 | |
62 | return true; |
63 | } |
64 | |
65 | int main(int, char**) { |
66 | test(); |
67 | static_assert(test()); |
68 | |
69 | return 0; |
70 | } |
71 | |