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 | // constexpr void constexpr void set_brackets(basic_string_view<charT> opening, |
18 | // basic_string_view<charT> closing) noexcept; |
19 | |
20 | #include <format> |
21 | #include <cassert> |
22 | #include <iterator> |
23 | #include <type_traits> |
24 | #include <vector> |
25 | |
26 | #include "make_string.h" |
27 | #include "test_format_context.h" |
28 | |
29 | #define SV(S) MAKE_STRING_VIEW(CharT, S) |
30 | |
31 | template <class CharT> |
32 | constexpr void test_setter() { |
33 | std::formatter<std::vector<int>, CharT> formatter; |
34 | formatter.set_brackets(SV("open" ), SV("close" )); |
35 | // Note the SV macro may throw, so can't use it. |
36 | static_assert(noexcept(formatter.set_brackets(std::basic_string_view<CharT>{}, std::basic_string_view<CharT>{}))); |
37 | |
38 | // Note there is no direct way to validate this function modified the object. |
39 | if (!std::is_constant_evaluated()) { |
40 | using String = std::basic_string<CharT>; |
41 | using OutIt = std::back_insert_iterator<String>; |
42 | using FormatCtxT = std::basic_format_context<OutIt, CharT>; |
43 | |
44 | String result; |
45 | OutIt out = std::back_inserter(result); |
46 | FormatCtxT format_ctx = test_format_context_create<OutIt, CharT>(out, std::make_format_args<FormatCtxT>()); |
47 | formatter.format(std::vector<int>{0, 42, 99}, format_ctx); |
48 | assert(result == SV("open0, 42, 99close" )); |
49 | } |
50 | } |
51 | |
52 | constexpr bool test() { |
53 | test_setter<char>(); |
54 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
55 | test_setter<wchar_t>(); |
56 | #endif |
57 | |
58 | return true; |
59 | } |
60 | |
61 | int main(int, char**) { |
62 | test(); |
63 | static_assert(test()); |
64 | |
65 | return 0; |
66 | } |
67 | |