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
6 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10 // TODO FMT Investigate why this fails.
11 // UNSUPPORTED: stdlib=apple-libc++ && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0|12.0}}
15 // template<ranges::input_range R, class charT>
16 // requires (K == range_format::string || K == range_format::debug_string)
17 // struct range-default-formatter<K, R, charT>
19 // template<class ParseContext>
20 // constexpr typename ParseContext::iterator
21 // parse(ParseContext& ctx);
23 // Note this tests the basics of this function. It's tested in more detail in
24 // the format.functions test.
30 #include "format.functions.tests.h"
31 #include "test_format_context.h"
32 #include "test_macros.h"
34 template <class FormatterT
, class StringViewT
>
35 constexpr void test_parse(StringViewT fmt
, std::size_t offset
) {
36 using CharT
= typename
StringViewT::value_type
;
37 auto parse_ctx
= std::basic_format_parse_context
<CharT
>(fmt
);
39 static_assert(std::semiregular
<decltype(formatter
)>);
41 std::same_as
<typename
StringViewT::iterator
> auto it
= formatter
.parse(parse_ctx
);
42 assert(it
== fmt
.end() - offset
);
45 template <class StringViewT
>
46 constexpr void test_formatters(StringViewT fmt
, std::size_t offset
) {
47 using CharT
= typename
StringViewT::value_type
;
48 test_parse
<std::formatter
<test_range_format_string
<std::basic_string
<CharT
>>, CharT
>>(fmt
, offset
);
49 test_parse
<std::formatter
<test_range_format_debug_string
<std::basic_string
<CharT
>>, CharT
>>(fmt
, offset
);
52 template <class CharT
>
53 constexpr void test_char_type() {
54 test_formatters(SV(""), 0);
55 test_formatters(SV("}"), 1);
58 constexpr bool test() {
59 test_char_type
<char>();
60 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
61 test_char_type
<wchar_t>();
67 int main(int, char**) {
69 static_assert(test());